Currently I have a website running which allows the user to enter a password into a . The form calls a doPost() to a Java HttpServlet file, which then checks if the field entered was correct or not.
Depending on the condition, it either redirect to TryAgain or Menu page using the following
request.getRequestDispatcher("/WEB-INF/FOLDERNAME/Menu.jsp").forward(
request, response);
This part works okay, but once I am on the Menu page I have two hyperlinks which should redirect to either /WEB-INF/FOLDERNAME/Multi.jsp or /WEB-INF/FOLDERNAME/Single.jsp
I need to keep these pages only accessible by users who signed in successfully on the initial password form page, so I put these inside of my /WEB-INF/ folder.
The problem I am having is how do I redirect to the appropriate page (Multi.jsp/Single.jsp) using HTML? I think it is a bit of an overkill to wire these two hyperlinks to two individual forms and call the request.getRequestDispatcher().forward(); from doPost(){} just to redirect a user.
Is there a different way to go about doing this?
I figured out a method, and would like to share it with others.
On my Menu.jsp I created a with two href attributes
<nav>
<ul>
<li><a href="../FOLDER/menu-servlet?roster">Upload Roster File</a></li>
<li><a href="../FOLDER/menu-servlet?manual">Manual Order</a></li>
</ul>
</nav>
This called my HttpServlet doGet() method. Inside of here, I was able to grab the query string, which is the text following in the url.
Then I did a simple if comparison in my doGet() method.
String queryString =request.getQueryString();
// PrintWriter out = response.getWriter();
// out.println(request.getQueryString());
//check where to redirect
if (queryString.equals("roster")) {
//redirect to Roster Upload jsp
request.getRequestDispatcher("/WEB-INF/FOLDER/Roster.jsp").forward(request, response);
} else if (queryString.equals("manual")) {
//redirect to Manual Generation jsp
request.getRequestDispatcher("/WEB-INF/FOLDER/ManualOrder.jsp").forward(
request, response);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.