先上代码:
package zds.shixun.sims.servlet.studentinfo;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import zds.shixun.sims.model.UserInfo;
import zds.shixun.sims.util.DBTools;
public class UpdatePassword extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String oldpassword = request.getParameter("oldpassword");
String newpassword = request.getParameter("newpassword");
System.out.println("======1=========");
UserInfo ri = (UserInfo) request.getSession().getAttribute("loginUser");
System.out.println("=========2===========================");
String password =ri.getPassWord();
System.out.println("=========3===========================");
if(!(password.equals(oldpassword))){
request.getSession().setAttribute("alertInfo", "原始密码输入错误,请重新输入!");
response.sendRedirect("./jsp/alertinfo.jsp");
}else{
DBTools dbt = new DBTools();
// UPDATE `mysql`.`help_category` SET `name`='Geographics' WHERE
// `help_category_id`=1;
StringBuffer sb = new StringBuffer(
"update userinfo set password='");
sb.append(newpassword).append("' ").append("where username='")
.append(ri.getUserName()).append("'");
int reus = dbt.executeUpdate(sb.toString());
if (reus > 0) {
UserInfo ri1 = new UserInfo();
ri1.setPassWord(newpassword);
ri1 = ri1.login(ri);
request.getSession().setAttribute("loginUser", ri1);
request.getSession().setAttribute("alertInfo", "密码修改成功,请重新登陆!");
} else {
request.getSession().setAttribute("alertInfo", "密码修改时发生错误!");
}
}
response.sendRedirect("./jsp/alertInfo.jsp");
}
}
以下试运行时候错误:
======1=========
=========2===========================
2012-6-20 19:01:59 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet UpdatePassword threw exception
java.lang.NullPointerException
at zds.shixun.sims.servlet.studentinfo.UpdatePassword.doPost(UpdatePassword.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
at java.lang.Thread.run(Thread.java:662)
求大神解救 |
|