New paste Repaste Download
Here’s how you can create the success page and failure page, along with the correct query for redirecting in your servlet for transaction processing.
1. HTML Pages
Success Page (success.html)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Success</title>
    <style>
        body {
            margin: 0;
            font-family: Arial, sans-serif;
            background-color: #f0f9f0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .success-box {
            background-color: #d4edda;
            color: #155724;
            padding: 20px;
            border-radius: 10px;
            text-align: center;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            width: 300px;
        }
    </style>
</head>
<body>
    <div class="success-box">
        <h2>Transaction Successful</h2>
        <p>Your transaction has been processed successfully!</p>
    </div>
</body>
</html>
Failure Page (failure.html)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Failure</title>
    <style>
        body {
            margin: 0;
            font-family: Arial, sans-serif;
            background-color: #f9f0f0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .failure-box {
            background-color: #f8d7da;
            color: #721c24;
            padding: 20px;
            border-radius: 10px;
            text-align: center;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            width: 300px;
        }
    </style>
</head>
<body>
    <div class="failure-box">
        <h2>Transaction Failed</h2>
        <p>There was an error processing your transaction. Please try again later.</p>
    </div>
</body>
</html>
2. Redirect Query in Servlet
In your servlet handling the transaction processing, you can use the following logic to redirect based on the transaction outcome.
Example Code in Servlet:
// Assume you have logic to check transaction success
boolean transactionSuccess = // Your transaction logic here
if (transactionSuccess) {
    // Redirect to success page
    response.sendRedirect("success.html");
} else {
    // Redirect to failure page
    response.sendRedirect("failure.html");
}
3. How This Works
• If the transaction is successful, the servlet redirects to success.html, displaying the success page.
• If the transaction fails, the servlet redirects to failure.html, displaying the failure page.
• No query string (?status=...) is necessary in this case since you are directly redirecting to static HTML pages.
This approach is clean and straightforward for showing simple success or failure messages.
Filename: None. Size: 3kb. View raw, , hex, or download this file.

This paste expires on 2024-12-25 04:55:19.617298. Pasted through web.