
已解决问题
谷歌nntuzgnn用户在提交了关于“悦翔v5关于request.getParameter和session.getAttribute”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-12-14T01:14:12。我想从一个页面:ex24.jsp中输入用户名,在另外个页面ex24_2.jsp中显示出来。主要代码:ex24.jsp====================================================================
<formid="form1"name="form1"method="post"action="ex24.jsp"onsubmit="returnon_submit()">
.
.
.
scriptlanguage="j**ascript"type="text/j**ascript">
functionon_submit(){
if(form1.name.value=="")
{
alert("name不能为空");
form1.name.focus();
returnfalse;
}
if(form1.password.value=="")
{
alert("password不能为空");
form1.passsword.focus();
returnfalse;
}
}
</script>
<%!
publicStringcodetoString(Stringstr){
Strings=str;
try{
bytetemp[]=s.getBytes("iso-8859-1");
s=newString(temp);
returns;
}catch(Exceptione)
{returns;}
}
%>
<%
Stringname=request.getParameter("name");
Stringpassword=request.getParameter("password");
if(name!=**ll&password!=**ll)
{
session.setAttribute("name",codetoString(name));
response.sendRedirect("ex24_2.jsp");
}
%>
ex24_2.jsp代码:
<%!
publicStringcodetoString(Stringstr){
Strings=str;
try{
bytetemp[]=s.getBytes("iso-8859-1");
s=newString(temp);
returns;
}catch(Exceptione)
{returns;}
}
%>
<body>
欢迎你:<%=codetoString(request.getParameter("name"))%></br>
用户名:<%=(String)session.getAttribute("name")%>
</body>
问题:为什么request.getParameter("name")获得的name为**ll;
把formid="form1"name="form1"method="post"action="ex24.jsp"
改为:
formid="form1"name="form1"method="post"action="ex24_2.jsp"
session.getAttribute("name")却为**ll了。
为什么?希望大家能够帮助她。
详细问题描述及疑问:我想从一个页面:ex24.jsp中输入用户名,在另外个页面ex24_2.jsp中显示出来。主要代码:ex24.jsp
====================================================================
<formid="form1"name="form1"method="post"action="ex24.jsp"onsubmit="returnon_submit()">
.
.
.
scriptlanguage="j**ascript"type="text/j**ascript">
functionon_submit(){
if(form1.name.value=="")
{
alert("name不能为空");
form1.name.focus();
returnfalse;
}
if(form1.password.value=="")
{
alert("password不能为空");
form1.passsword.focus();
returnfalse;
}
}
</script>
<%!
publicStringcodetoString(Stringstr){
Strings=str;
try{
bytetemp[]=s.getBytes("iso-8859-1");
s=newString(temp);
returns;
}catch(Exceptione)
{returns;}
}
%>
<%
Stringname=request.getParameter("name");
Stringpassword=request.getParameter("password");
if(name!=**ll&password!=**ll)
{
session.setAttribute("name",codetoString(name));
response.sendRedirect("ex24_2.jsp");
}
%>
ex24_2.jsp代码:
<%!
publicStringcodetoString(Stringstr){
Strings=str;
try{
bytetemp[]=s.getBytes("iso-8859-1");
s=newString(temp);
returns;
}catch(Exceptione)
{returns;}
}
%>
<body>
欢迎你:<%=codetoString(request.getParameter("name"))%></br>
用户名:<%=(String)session.getAttribute("name")%>
</body>
问题:为什么request.getParameter("name")获得的name为**ll;
把formid="form1"name="form1"method="post"action="ex24.jsp"
改为:
formid="form1"name="form1"method="post"action="ex24_2.jsp"
session.getAttribute("name")却为**ll了。
为什么?期待您的答案,希望你能感受到,我最真诚的谢意
!