Is there any specific available method in jsp/Servlet API which tell you from which page the request is being redirected

前端 未结 2 1025
盖世英雄少女心
盖世英雄少女心 2021-01-17 02:28

I have been working in Oracle iStore from past 4 months and I have been managing the application without any IDE (basically doing all the chores on notepad only because appl

2条回答
  •  温柔的废话
    2021-01-17 02:41

    An easy way would be grabbing the (legendaric misspelled) HTTP referer header. You can get it in a Servlet as follows:

    String referrer = request.getHeader("referer");
    

    And in a JSP as follows:

    ${header.referer}
    

    You should however realize that this is a client-controlled value and can be changed/spoofed/hacked to something entirely different or even removed.

    If you want a bit more reliable approach, then you'll really need to add an extra parameter to the request. In a plain vanilla link you can set it as a query string.

    go to b.jsp
    

    or as a hidden input element in a form:

    ...

    Either way, you can get in a Servlet as follows:

    String from = request.getParameter("from");
    

    or in a JSP as follows:

    ${param.from}
    

提交回复
热议问题