多个JSP页面之间进行参数传递


需要使用JSP的内置作用域对象session。利用它的两个方法setAttribute(),getAttribute()

2.下面的这个实例实现了把第一个JSP页面的参数传递给第三个页面的功能

3.代码如下:1.jsp

<html>

<formmethod=get action=2.jsp>

what'syour name<input type=text name=username>

<inputtype=submit value=submit>

</form>

</html>

4.2.jsp

<html>

<formmethod=post action="3.jsp">

<%

Stringname=request.getParameter("username");

session.setAttribute("username",name);

%>

Yourname is:<%=request.getParameter("username")%>

<br>

    what's your hobby<input type=textname=hobby>

    password<input type=textname=password>

<inputtype=submit value=submit>

</form>

</html>

5.3.jsp

<html>

yourname is:<%=session.getAttribute("username")%>

<br>

yourhobby is:<%=request.getParameter("hobby")%>

yourpassword is:<%=request.getParameter("password")%>

原文地址:https://www.cnblogs.com/liaoshiyong/p/3150826.html