以下是一个简单注册页面的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: {请问为什么会这样?

解决方案 »

  1.   

    你不能只写jsp吧,它能自动找你的路径吗?写个路径试试。
      

  2.   

    可以啊 action都是jsp文件写的 jsp文件都在同一个目录下面
      

  3.   

    问题应该出在你使用response.sendRedirect("login.jsp"); 方法不正确,response是重新定向,你这么写找不到你这个jsp文件的 ,把路径加上,或者使用return mapping.findForward();(建议使用)
      

  4.   

    try一下:<% request.getRequestDispatcher("register.jsp").forward(request,rsponse);%>
      

  5.   

    跳转之后应该return掉
    if(username == null || password1 == null || password2 == null || !password1.equals(password2))
    {
        response.sendRedirect("register.jsp");
        return;
    }
      

  6.   

    hey man!you are right
    thank you!