网页传值问题解决

1.jsp

    <form method="get" action="2.jsp"> 
         what's your name
        <input type="text" name="username"> 
        <input type="submit" value="submit"> 
    </form>

2.jsp

<form method="post" action="3.jsp"> 
       <%String name=request.getParameter("username"); 
        session.setAttribute("username",name); 
        %> 
       Your name is:
        <%=request.getParameter("username")%> 
       <br>what's your hobby
        <input type=text name=hobby> 
       <input type=submit value=submit> 
       </form>

3.jsp

       your name is:<%=session.getAttribute("username")%> 
       <br> 
       your hobby is:<%=request.getParameter("hobby")%> 
       <br> 
       </form> 

session存储周期长,不安全

request存储周期短,安全

 

posted @ 2020-02-01 21:23  cts1234  阅读(127)  评论(0编辑  收藏  举报