Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 601399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:42:38+00:00 2026-05-13T16:42:38+00:00

I’m taking a class on JSP and I have an assignment… we have to

  • 0

I’m taking a class on JSP and I have an assignment… we have to write a JSP page that takes user input, validate the input and then forward it to a different web site. To be more precise, we were asked to implement a rudimentary version of the FareFinder functionality of Amtrak’s web site.

There are 2 main purposes to this assignment:
(a) to write JSP which performs as middleware;
and (b) to write JSP which validates form data.

I have a general question about the principles of doing the validation. Currently I have a JSP that has a form and a submit button. When the user clicks on the submit button I forward them to Validate.jsp. The Validate.jsp will then validate the data and if the input is OK it will automatically redirect the request to the Amtrak web site with all the parameters filled out.

FareFinder.jsp -> Validate.jsp -> Amtrak
(click on the file name to see all my code in a pastie)

Briefly, the main thing that I’m doing FareFinder.jsp:

<FORM METHOD=POST ACTION="Validate.jsp">
    <!-- all the input fields are up here -->
    <P><INPUT TYPE=SUBMIT></P>
</FORM>

The main thing I’m doing in Validate.jsp:

<%@ page import="java.util.*" import="java.io.*"%>
<%
    // retreive all the parameters
    String origin = request.getParameter("_origin");
    String depmonthyear = request.getParameter("_depmonthyear");
    String depday = request.getParameter("_depday");
    String dephourmin = request.getParameter("_dephourmin");
    String destination = request.getParameter("_destination");
    String retmonthyear = request.getParameter("_retmonthyear");
    String retday = request.getParameter("_retday");
    String rethourmin = request.getParameter("_rethourmin");
    String adults = request.getParameter("_adults");
    String children = request.getParameter("_children");
    String infants = request.getParameter("_infants");
    String searchBy = request.getParameter("_searchBy");

    // validate the data

    // redirect to Amtrak or back to FareFinder.jsp
%>

I have several questions:
How do I return to FareFinder.jsp from Validate.jsp and reflect the errors found in the validation page?
Once I have found errors- do I redirect the response back to FareFinder.jsp?
How could I transmit the error(s) back to FareFinder.jsp?

A generic answer would be fine too, but I’m giving my code as an example.

Note: the validation must be performed on the server side and I can’t use javascript.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:42:39+00:00Added an answer on May 13, 2026 at 4:42 pm

    OK, as per the comments, Servlets are covered as well. Now, create one and implement doPost() like follows (semi pseudo):

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map<String, String> errors = new HashMap<String, String>();
    
        String origin = request.getParameter("origin");
        if (origin does not validate) {
           errors.put("origin", "Put error message here.");
        }
    
        // Repeat for all parameters.
    
        if (errors.isEmpty()) {
            // No errors, redirect to Amtrak.
            response.sendRedirect("http://amtrak.com");
        } else {
            // Put errors in request scope and forward back to JSP.
            request.setAttribute("errors", errors);
            request.getRequestDispatcher("FareFinder.jsp").forward(request, response);
        }
    }
    

    Map this servlet in web.xml on an url-pattern of /validateFare so that you can invoke it by http://example.com/context/validateFare.

    Now do in JSP something like:

    <form action="validateFare" method="post">
        <label for="origin">Origin</label>
        <input id="origin" name="origin" value="${param.origin}">
        <span class="error">${errors.origin}</span>
    
        <!-- Repeat other fields here. -->
    </form>
    

    You see that the form action already points to the servlet. The ${param.origin} in input values will retain the submitted value by doing request.getParameter("origin") under the hoods. The ${errors.origin} will show any associated error message by roughly doing pageContext.findAttribute("errors").get("origin").

    This must get you started 🙂 Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.