简体   繁体   中英

How to respond to 'included' JSPs from Servlets

I have a login.jsp form that I have written for a website that just contains a form for logging in that I can include and re-use in different places. The first place I am including it is in my index.jsp homepage.

I have an HTTPServlet that the form submits to, and if the username/password is invalid the Servlet sends a message back to display to the user, otherwise it forwards them on to their homepage.

My problem is that I want to forward them back to the same page they're on if their details are incorrect, but display the message, but forwarding to the login page displays only that form in the browser, outside of the page it was included in. Is there any way I can forward back to the current page? Or is this perhaps not the best way to go about this?

Thanks for reading.

I am presuming you are using a <jsp:include> . Here is something you might do:

<jsp:include page="loginForm.html">
    <jsp:param name="currentPage" value="${whateverTheCurrentPageIs}" />
</jsp:include>

Include the currentPage variable in the loginForm. Then, in your servlet, you want to redirect/forward to the URL you passed in that currentPage variable.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM