There is a starting page ( index.jsp ) which is a menu and links from it lead to jsp files that are in WEB-INF . But when I use the <a href="addition.jsp">Добавить пользователя</a> I get a 404 error. Previously, I had all the files right in the webapp and they could be accessed just by building the URL but now I got the task to ensure security by placing all jsp files in WEB-INF . And internal navigation links no longer work.

Please help me, how can I ensure the transition to the page that lies in WEB-INF ?

So I drop my index.jsp and addition.jsp to which I should get via the link <a href="addition.jsp"> which is on the index.jsp page:

 <!--Homepage.--> <servlet> <servlet-name>HomePageServlet</servlet-name> <servlet-class>ru.pravvich.servlets.HomePageServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HomePageServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!--Add user in database.--> <servlet> <servlet-name>AddUserServlet</servlet-name> <servlet-class>ru.pravvich.servlets.AddUserServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>AddUserServlet</servlet-name> <url-pattern>/addition</url-pattern> </servlet-mapping> 

This is the servlet that gives index.jsp:

 public class HomePageServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF8"); req.getRequestDispatcher("/WEB-INF/views/index.jsp").forward(req,resp); } } 

And my index.jsp

 <body> <h2>Меню</h2><br /> <ul> <li><a href="addition.jsp">Добавить пользователя</a></li> </ul> </body> 

How can this be done without crutches? Thank.

  • one
    Neither WEB-INF, nor what is in it is available for navigation in the browser in principle. If you have a link on the page href = "addition.jsp", then you must either have addition.jsp in the webapp, or the url of addition.jsp should be mapped to some servlet. Nevertheless, WEB-INF is available for servlets and jsp, via the same dispatcher.forward or include - Sergey
  • one
    Usually jsp protected in this way are view templates. They are available only through servlet controllers. On the page, the links are shown not on the jsp, but on the url of the servlet. And the servlet, having executed everything it has to do, to generate the page, forwards on jsp, hidden in WEB-INF. Those. should be href = "addition" instead of href = "additin, jsp" - Sergey
  • one
    href can also be used. In principle, there is no difference between action in a form and href in a. And here and there you need to put the url of the servlet. In the servlet, you can recognize whether the link was followed or the form was submitted (doGet | doPost), take appropriate measures and substitute any jsp depending on the conditions - Sergey
  • one
    When a link is clicked, doGet () is triggered in the servlet. <a> method is not needed. He always GET. If the form is set to method = "POST", then doPost () is triggered. This can be used to distinguish one from the other. - Sergey
  • one
    And besides processing and result depend on the entering parameters. There are they, they are not, to which they are equal, All this forms the conditions on which certain actions are taken. There is a request button parameter in the request, it means that you must perform addition, show jsp with the result, No - show the data entry jsp. It's simple. - Sergey

0