首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsp页面的传值有关问题

2011-12-23 
jsp页面的传值问题index.jspformaction test131.jsp method post label 请输入用户名inputname

jsp页面的传值问题
index.jsp
<form   action= "test131.jsp "   method= "post ">
    <label> 请输入用户名
    <input   name= "name "   type= "text "     />
    </label>
    <p>
        <label> 请输入验证码
        <input   name= "password "   type= "text "     />
        </label>
        </p>
    <p>
        <label>
        <input   type= "submit "   name= "Submit "   value= "提交 "   />
        </label>
    </p>
</form>

test131.jsp
<%   String   name=request.getParameter( "name ");
      String   password=request.getParameter( "password ");
   
      if(password.equals( "go ")){
                    session.setAttribute( "name ",name);
                    session.setAttribute( "mess ", "你好,你已经验证成功! ");
                }else{
                    session.setAttribute( "name ",name);
                    session.setAttribute( "mess ", "你好,请你重新登陆! ");
                }
                response.sendRedirect( "test132.jsp ");
%>

test132.jsp
<%  
        String   name=(String)session.getAttribute( "name ");
        String   mess=(String)session.getAttribute( "mess ");
        if(name.equals( "null ")){
                    out.println( "请通过验证! ");
        }else{
                    out.println( "name ");
                    out.println( "mess ");
        %>
<form   action= "test131.jsp "   method= "post ">
    <label> 请输入姓名
    <input   type= "text "   name= "name "   />
    </label>
    <p>
        <label> 请输入验证码
        <input   name= "password "   type= "text "     />
        </label>
    </p>
    <p>
        <label>
        <input   type= "submit "   name= "Submit "   value= "验证 "   />
        </label>
    </p>
</form>
          <%   }   %>
运行到是能够运行,就是name和mess的值传不过去
大家帮我看下谢谢



[解决办法]
大哥,可以传阿

ss.jsp
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<% String name= "ss ";
String password= "go ";

if(password.equals( "go ")){
session.setAttribute( "name ",name);
session.setAttribute( "mess ", "你好,你已经验证成功! ");
}else{
session.setAttribute( "name ",name);
session.setAttribute( "mess ", "你好,请你重新登陆! ");
}
response.sendRedirect( "tt.jsp ");
%>

tt.jsp
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<%
String name=(String)session.getAttribute( "name ");
String mess=(String)session.getAttribute( "mess ");
if(name.equals( "null ")){
out.println( "请通过验证! ");
}else{
out.println( "name: "+name);
out.println( "mess: "+mess);
%>
<form action= "ss.jsp " method= "post ">
<label> 请输入姓名
<input type= "text " name= "name " />
</label>
<p>
<label> 请输入验证码
<input name= "password " type= "text " />
</label>
</p>
<p>
<label>
<input type= "submit " name= "Submit " value= "验证 " />
</label>
</p>
</form>
<% } %>

结果:

name:ss mess:你好,你已经验证成功!

热点排行