<%@ page contentType="text/html;charset=gb2312" %>
<HTML>
<body bgcolor=cyan><font size=3>
<%! public String handleStr(String s) {
try { byte [] bb= s.getBytes("iso-8859-1");
s = new String(bb);
}
catch(Exception exp){}
return s;
}
%>
<form action="" method=post name=form>
<table border=0>
<tr>
<td>*用户名称:<input type="text" name="username" value="names"/></td>
<td>*用户密码:<input type="password" name="userpassword" value="passwords"/></td>
</tr>
<tr>
<td>*重复密码:<input type="password" name="aginpassword" value="aginpasswords"/></td>
<td>*联系电话:<input type="text" name="userphone" value="phone"/></td>
</tr>
<tr>
<td>邮寄地址:<input type="text" name="useraddress" value="names"/></td>
<td>真实姓名:<input type="text" name="truename" value="truenames"/></td>
</tr>
</table>
<input type="submit" value="提交"/>
</form>
<%
String username=request.getParameter("username");
String userpassword=request.getParameter("userpassword");
String aginpassword=request.getParameter("aginpassword");
String userphone=request.getParameter("userphone");
boolean cg=true;
for(int i=0;i<username.length();i++){
char c=username.charAt(i);
if(!((c<='z'&&c>='a')||(c<='Z'&&c>='A')||(c<='9'&&c>='0')||(c=='_')))
cg=false;
}
if(username==null||username.length()>0||userpassword==null||userpassword.length()>0||aginpassword==null||aginpassword.length()>0||userphone==null||userphone.length()>0){
cg=false;
}
if(!cg){
out.println("注册反馈:注册失败<br>");
}else{
out.println("注册反馈:注册成功<br>");
%>
<table border=2>
<tr>
<td>会员名称:</td>
<td><%
out.println(""+handleStr(username)); %></td>
</tr>
<tr>
<td>姓名:</td>
<td><% String truenameaa=request.getParameter("truename");
if(truenameaa==null||truenameaa.length()==0) {
response.sendRedirect("example3_12.jsp");
}
out.println(""+handleStr(truenameaa)); %>
</td>
</tr>
<tr>
<td>地址:</td>
<td><% String useraddress=request.getParameter("useraddress"); out.println(""+handleStr(useraddress));%></td>
</tr>
<tr>
<td>电话:</td>
<td><% String userphoneaa=request.getParameter("userphone"); out.println(""+handleStr(userphoneaa));%></td>
</tr>
</table>
<%
}
%>
</font></body></HTML>
下面是ie浏览器提示的错误!!!
type Exception report
message An exception occurred processing JSP page /huazhuangpin/inputRegister.jsp at line 36
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /huazhuangpin/inputRegister.jsp at line 36 33: String aginpassword=request.getParameter("aginpassword"); 34: String userphone=request.getParameter("userphone"); 35: boolean cg=true; 36: for(int i=0;i<username.length();i++){ 37: char c=username.charAt(i); 38: if(!((c<='z'&&c>='a')||(c<='Z'&&c>='A')||(c<='9'&&c>='0')||(c=='_'))) 39: cg=false; Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:580) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
额,表示没看懂你在干啥。你这是获取request中的username?在你认为你这段java代码是什么时候执行的?你是打算点击提交的时候判断是不是为空么?不为空就注册成功?为空就注册失败?
嗯你看懂了这不是,但是一运行就出错,就说for(int i=0;i<username.length();i++){
这行代码有错,怎么解啊
@凉白开的你: 。。。不是看懂了,这是猜的。因为你这样写就代表着页面一开始就会执行这段代码。而不是在你点击提交的时候。这逻辑是在你点击之后再执行,而不是页面一开始就执行。简单来说:这样写逻辑就是错了。
你为什么这段逻辑不写在你的“提交”操作的后台方法里面。
@蜀黎peng: 嗯嗯知道了,谢谢园友,已经解决。但是我逻辑思维特别差,也是好气哟
@凉白开的你: 好气哦 //斜眼笑 。 多写写就好了,加油