How to forward the parameters from one page to another jsp page?

前端 未结 1 1479
春和景丽
春和景丽 2020-12-19 15:48

Am New to jsp I had to forward the name from one file to another. After a lot of dig I found the below code to be worked but it wasn\'t work. I have three jsp files like one

相关标签:
1条回答
  • 2020-12-19 16:22

    Consider the code below on how you can pass parameters between jsp pages. You can use the <jsp:forward ... > to forward a request using this code:

    <jsp:forward page="newjsp1.jsp">
      <jsp:param name="par1" value="111" ></jsp:param>
    </jsp:forward>
    

    This will forward the response to newjsp1.jsp with a parameter par1 and its value is 111.

    Now in newjsp1.jsp you can read this parameter using:

    <jsp:scriptlet>
      out.append(request.getParameter("par1"));
    </jsp:scriptlet>
    

    You can also share attributes between pages using the session implicit Object... Possibilities are limitless...

    Maybe you would like to check these pages out:

    1. http://www.tutorialspoint.com/jsp/jsp_implicit_objects.htm
    2. http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
    0 讨论(0)
提交回复
热议问题