以下是一个简单注册页面的action代码<%@ page pageEncoding="gb2312"%>
<%@ include file="inc.jsp"%>
<%
String username = request.getParameter("username");
String password1 = request.getParameter("password1");
String password2 = request.getParameter("password2");
String email = request.getParameter("email");//检查是否为空
if(username == null || password1 == null || password2 == null || !password1.equals(password2))
{
response.sendRedirect("register.jsp");
}//验证用户名是否存在
boolean isValid=false;
String sql = "select * from user where username='"+username+"'";
try
{
Class.forName(drv).newInstance();
Connection conn = DriverManager.getConnection(url,usr,pwd);
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery(sql);
if(!rs.next())
{
sql="insert into user(username,password,email) values('"+username+"','"+password1+"','"+email+"')";
stm.execute(sql);
isValid = true;
}
rs.close();
stm.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
out.println(e);
}if(isValid)
{
response.sendRedirect("login.jsp");
}
else
{
response.sendRedirect("register.jsp");
}
%>
inc.jsp 里是对drv,url,usr,pwd等等的定义每次执行下面if里的页面跳转时都会出错,不执行这个跳转就不会出错//检查是否为空
if(username == null || password1 == null || password2 == null || !password1.equals(password2))
{
response.sendRedirect("register.jsp");
}
错误信息:
type Exception report
message
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 /register_action.jsp at line 42
39:
40: if(isValid)
41: {
42: response.sendRedirect("login.jsp");
43: }
44: else
45: {请问为什么会这样?
<%@ include file="inc.jsp"%>
<%
String username = request.getParameter("username");
String password1 = request.getParameter("password1");
String password2 = request.getParameter("password2");
String email = request.getParameter("email");//检查是否为空
if(username == null || password1 == null || password2 == null || !password1.equals(password2))
{
response.sendRedirect("register.jsp");
}//验证用户名是否存在
boolean isValid=false;
String sql = "select * from user where username='"+username+"'";
try
{
Class.forName(drv).newInstance();
Connection conn = DriverManager.getConnection(url,usr,pwd);
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery(sql);
if(!rs.next())
{
sql="insert into user(username,password,email) values('"+username+"','"+password1+"','"+email+"')";
stm.execute(sql);
isValid = true;
}
rs.close();
stm.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
out.println(e);
}if(isValid)
{
response.sendRedirect("login.jsp");
}
else
{
response.sendRedirect("register.jsp");
}
%>
inc.jsp 里是对drv,url,usr,pwd等等的定义每次执行下面if里的页面跳转时都会出错,不执行这个跳转就不会出错//检查是否为空
if(username == null || password1 == null || password2 == null || !password1.equals(password2))
{
response.sendRedirect("register.jsp");
}
错误信息:
type Exception report
message
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 /register_action.jsp at line 42
39:
40: if(isValid)
41: {
42: response.sendRedirect("login.jsp");
43: }
44: else
45: {请问为什么会这样?
if(username == null || password1 == null || password2 == null || !password1.equals(password2))
{
response.sendRedirect("register.jsp");
return;
}
thank you!