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

前端 未结 2 1006
盖世英雄少女心
盖世英雄少女心 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.

    <a href="b.jsp?from=a.jsp">go to b.jsp</a>
    

    or as a hidden input element in a form:

    <form action="b.jsp" method="post">
        <input type="hidden" name="from" value="a.jsp">
        ...
    

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

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

    or in a JSP as follows:

    ${param.from}
    
    0 讨论(0)
  • 2021-01-17 02:45

    use request.getHeader("Referer");

    0 讨论(0)
提交回复
热议问题