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" />
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" />
解决方案 »
- JAVA POI 读日期类型时实际读到number类型数字,如何得到原来的显示的日期呢
- spring 中如何在循环中绑定命令对象?
- 租过服务器的请进
- 请问一下JSP有无类似ASP的response.end
- UP有分!请教~~在servlet中如何包含另一个工程中的jsp或servlet文件?(include方法)
- 关于java反编译的技巧,请大家一起来共享
- 参考了N多文章还是连接数据库失败,谁能来帮我解释下这是什么错误
- 数据库连接池DBConnectionManager中的释放问题!
- Java中调用C++的组件,怎么实现啊?
- 如何将数据叠加的保存到数据库
- struts页面跳转问题
- 关于websrevice的问题
在 <forward name="success" path="/ADhanz.do" />
中path="ADhanz.do"改成path="modify_all.jsp"也是直接跳转到error.jsp
没有提示任何错误信息!
<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的配置的几个属性,你检查下是不是有写错了
return mapping.findForward("fail");
}
改成
}catch (Exception e) {
e.printStackTrace();
return mapping.findForward("fail");
}
看看有什么异常。还有就是3楼的建议。
这句代码没有执行!!debug一下
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, username);
ResultSet rs=ps.executeQuery();
rs.next();这些代码放到Dao中编写
在控制里不要写sql语句不太规范!
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()里面的空异常!呵呵,,不要偷简单啊!所有的异常都处理好了,自己就知道原因在哪里了?