I take a class on JSP and I have a task ... we need to write a JSP page that enters user input, validates the input and then redirects it to another website. To be more precise, we were asked to implement a rudimentary version of the FareFinder functionality of the Amtrak website.
There are two main objectives in this assignment:
(a) write a JSP that acts as a middleware.
and (b) write a JSP that validates form data.
I have a general question about the principles of verification. I currently have a JSP that has a form and a submit button. When the user clicks the submit button, I forward them to Validate.jsp. Validate.jsp then validates the data, and if the login is ok, it automatically redirects the request to the Amtrak website with all the parameters filled in.
FareFinder.jsp β Validate.jsp β Amtrak
(click on the file name to see all my code in the paste)
In short, the main thing I do is FareFinder.jsp:
<FORM METHOD=POST ACTION="Validate.jsp"> <P><INPUT TYPE=SUBMIT></P> </FORM>
The main thing I do in Validate.jsp is:
<%@ 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 a few questions:
How can I go back to FareFinder.jsp from Validate.jsp and reflect the errors found on the check page?
As soon as I find errors - do I redirect the response back to FareFinder.jsp?
How can I pass the error (s) back to FareFinder.jsp?
The general answer will also be good, but I give the code as an example.
Note: validation must be done on the server side and I cannot use javascript.
java validation jsp
Kiril
source share