Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSP link to another JSP

Tags:

jsp

servlets

In my JSP page I want the links to forward to another JSP page. When the user is on the home.jsp I want them to go to login.jsp etc. The problem I am having is that the JSP can't be found except when i put the pages in the project folder (above the WEB-INF folder).

I tried these lines of code, but none worked:

<a href="/enq/WEB-INF/pages/login.jsp">
<a href="/WEB-INF/pages/login.jsp">
<a href="/pages/login.jsp">

It is only working with the JSP pages in the project folder and then I use the next line:

<a href="login.jsp">

But I want the JSP pages to be in: WEB-INF/pages/

like image 809
ronaldm Avatar asked Oct 25 '25 06:10

ronaldm


2 Answers

I have solved it, I have created 4 Servlets for each JSP page. Every servlet forwards the message to the corresponding JSP like this:

request.getRequestDispatcher("/WEB-INF/pages/enquette.jsp").forward(request, response);

And in the JSP page in between the a href :

<a href="/enq/enquette">

The web XML:

<servlet-mapping>
<servlet-name>Enquette</servlet-name>
<url-pattern>/enquette</url-pattern>
like image 104
ronaldm Avatar answered Oct 28 '25 03:10

ronaldm


<a href="/pages/login.jsp">

It must work properly. What HTTP status do you get in this case?

like image 21
kapandron Avatar answered Oct 28 '25 04:10

kapandron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!