📄 modifypasswddaction.java
字号:
/**
*
*/
package cn.bway.admin.action;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import cn.bway.common.LoginConstants;
import cn.bway.common.WebConstant;
import cn.bway.common.action.BaseAction;
import cn.bway.common.dao.HibernateSessionFactory;
/**
* @author Kson
*
*/
public class ModifyPasswddAction extends BaseAction {
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws SQLException
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,HttpServletRequest request, HttpServletResponse response) throws SQLException {
// UseloginForm pForm = (UseloginForm) form;
ActionErrors errors = new ActionErrors();
String returnStr = WebConstant.FORWARD_SUCCESS;
Session sess;
Connection conn=null;
//����get����
if(request.getMethod().equals("GET")){
// request.setAttribute(WebConstant.PAGE_Object, pForm);
returnStr = WebConstant.FORWARD_INITPAGE;
return mapping.findForward(returnStr);
}
try {
HttpSession session = request.getSession();
sess=HibernateSessionFactory.currentSession();
conn=sess.connection();
conn.setAutoCommit(false);
String username = (String)session.getAttribute(LoginConstants.GLOBLE_STAFF_NAME);
String newpassword = request.getParameter("newpassword");
String oldpassword=request.getParameter("oldpassword");
String tmpTableName = "staffinfo";
if(checkisuse(username,oldpassword,tmpTableName,conn)){
chagepassword(username,newpassword,tmpTableName,conn);
request.setAttribute(WebConstant.RETURN_Message,"������ɹ� ��w修改成功!");
}else{
request.setAttribute(WebConstant.RETURN_Message,"������������������� ��会员不存在,或密码错误!");
}
returnStr = WebConstant.FORWARD_SUCCESS;
conn.commit();
} catch (Exception e) {
returnStr=WebConstant.FORWARD_FAIL;
errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("edu.system.excption",e.getMessage()));
this.saveErrors(request,errors);
conn.rollback();
e.printStackTrace();
}
finally{
try {
if(null !=conn){
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HibernateSessionFactory.closeSession();
}
return mapping.findForward(returnStr);
}
//check the use oldpassword
private boolean checkisuse(String username,String oldpassword,String tableName,Connection conn){
PreparedStatement stat = null;
ResultSet rs = null;
String sql = "select * from "+ tableName +" where staffname = '"+username+"' " +
"and passward = '"+oldpassword+"' ";
try{
stat = conn.prepareStatement(sql);
rs = stat.executeQuery();
if(rs.next()){
return true;
}
}catch(Exception e){
e.printStackTrace();
} finally{
try {
rs.close();
stat.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return false;
}
//check the use password
private void chagepassword(String username,String newpwd,String tableName,Connection conn){
PreparedStatement stat = null;
ResultSet rs = null;
try{
String sql = "update "+ tableName +" set passward = '"+newpwd+"'" +
" where staffname = '"+username+"' ";
stat = conn.prepareStatement(sql);
int a = stat.executeUpdate();
}catch(Exception e){
e.printStackTrace();
} finally{
try {
stat.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -