top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

I would like to hide or protect URL of the jsp page, how can I do that?

+2 votes
730 views
I would like to hide or protect URL of the jsp page, how can I do that?
posted Sep 24, 2013 by Manish Negi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The JSP resources usually reside directly or under subdirectories (e.g. myPath) of the document root, which are directly accessible to the user through the URL. If you want to protect your Web resources then hiding the JSP files behind the WEB-INF directory can protect the JSP files, css (cascading style sheets) files, Java Script files, pdf files, image files, html files etc from direct access. The request should be made to a servlet who is responsible for authenticating and authorising the user before returning the protected JSP page or its resources.

You should really use servlets as controllers. You control your url with mapping a url to a servlet in web.xml and redirecting from that servlet to your JSP.

Link to your servlet from your tag.
like this
< a href="ResultServlet">Result < /a >

Assuming you have mapped your servlet correctly. Then the servlet handles the display by using RequestDispatcher object. Then forwards your request and response to your jsp page. lets say your
servlet is named ResultServlet here is the sample code in a servlet .

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        RequestDispatcher view = request.getRequestDispatcher("result.jsp");  
        view.forward(request, response);                  
} 

/** 
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 
 */  

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  

    doGet(request,response);  
}  
answer Sep 25, 2013 by Arvind Singh
...