public class adHanz extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// response.setContentType("text/html;charset=gbk");
adhanzForm adf=(adhanzForm)form;
String username=adf.getId();
String password=adf.getPasswd();
//System.out.println(password);
password=Encrypt.getMD5Message(password);
//System.out.println(password);
//System.out.println(username);
//System.out.println(password);
try{
Connection con=connectionFactory.getconnection();
String sql="select secpd from adm where id=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, username);
ResultSet rs=ps.executeQuery();
rs.next();
    //String psw=Encrypt.getMD5Message(password);
//System.out.println("1"+rs.getString(1));
if(password.equals(rs.getString(1)))
  {
HttpSession session=request.getSession();
session.setAttribute("username", username);
        //System.out.println(session.getAttribute("2"+"username"));
session.setMaxInactiveInterval(10);
connectionFactory.close(rs);
connectionFactory.close(ps);
connectionFactory.close(con);
return mapping.findForward("success");
  }
else
return mapping.findForward("fail");

}catch (Exception e) {
return mapping.findForward("fail");
}
}
}struts-config.xml部分 <action path="/ADhanz" forward="/modify_all.jsp" /> <action path="/adlogin" type="com.web.adhanz.adHanz"
name="adhanzForm" scope="session">
<forward name="success" path="/ADhanz.do" />
<forward name="fail" path="/error.jsp" />

解决方案 »

  1.   

    我是想输入用户名 密码验证成功后 跳转到 modify_all.jsp
    在 <forward name="success" path="/ADhanz.do" />
    中path="ADhanz.do"改成path="modify_all.jsp"也是直接跳转到error.jsp
    没有提示任何错误信息!
      

  2.   

    password.equals(rs.getString(1))这里的条件是true还是false?
      

  3.   

    struts-config.xml部分 的配置写错了吧,
    <action path="/ADhanz" forward="/modify_all.jsp" />
    如:
    <action path="/login" name="loginForm" scope="request"
    type="org.springframework.web.struts.DelegatingActionProxy"
    input="/login.jsp">
    <forward name="success" path="/welcome.jsp" />
    <forward name="failure" path="/login.jsp" />
    </action>
    这是struts1中action的配置的几个属性,你检查下是不是有写错了
      

  4.   

    }catch (Exception e) {
                return mapping.findForward("fail");
            }
    改成
    }catch (Exception e) {
                e.printStackTrace();
                return mapping.findForward("fail");
            }
    看看有什么异常。还有就是3楼的建议。
      

  5.   


    这句代码没有执行!!debug一下
      

  6.   

     String sql="select secpd from adm where id=?";
                PreparedStatement ps=con.prepareStatement(sql);
                ps.setString(1, username);
                ResultSet rs=ps.executeQuery();
                rs.next();这些代码放到Dao中编写
    在控制里不要写sql语句不太规范!
      

  7.   

    你那个方法里有很多的异常没有捕捉,直接转到errer.jsp页面去了,很多异常不能用一个异常去管理,那里许多的错误。你无法知道的! Connection con=connectionFactory.getconnection();
                String sql="select secpd from adm where id=?";
                PreparedStatement ps=con.prepareStatement(sql);
                ps.setString(1, username);
                ResultSet rs=ps.executeQuery();
                rs.next();
    这个里面,有连接异常,executeQuery查询异常。还有 rs.next()里面的空异常!呵呵,,不要偷简单啊!所有的异常都处理好了,自己就知道原因在哪里了?