问题描述
- jsp页面登录错误,doPost代码问题
-
这是ManageSevlet.java部分代码:
package wyf.zrk;import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;
import java.util.*;
import org.springframework.web.context.support.*;
import org.springframework.web.context.*;
import org.springframework.beans.factory.*;
import java.text.DateFormat;public class ManageServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
this.doPost(request,response); //调用doPost方法
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
request.setCharacterEncoding("gbk"); //设置请求编码格式
response.setCharacterEncoding("gbk"); //设置响应编码
response.setContentType("text/html;charset=gbk"); //设置请求页面格式
PrintWriter out = response.getWriter(); //得到输出流对象
HttpSession session = request.getSession();
UserBean userBean = (UserBean)session.getAttribute("userBean");
if(userBean==null){
userBean = new UserBean();
}
//获取WebApplicationContext
WebApplicationContext wac=
WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
DButil db = (DButil)wac.getBean("DButil");
DBinsert dbin = (DBinsert)wac.getBean("DBinsert");
DBupdate dbup = (DBupdate)wac.getBean("DBupdate");
DBdelete dbde = (DBdelete)wac.getBean("DBdelete");
String action = request.getParameter("action").trim(); //得到请求动作
if(action.equals("login")){ //动作为登陆时
String aname = request.getParameter("uname").trim();//得到用户名
String apwd = request.getParameter("upwd").trim(); //得到密码
aname = new String(aname.getBytes(),"ISO-8859-1"); //将用户名转码
apwd = new String(apwd.getBytes(),"ISO-8859-1"); //将密码转码
System.out.println(aname+"t"+apwd);
String hql = "from AdminInfo as p "+ //hql语句
"where p.aname='"+aname+"' and p.apwd='"+apwd+"'";
List list = (List)db.getInfo(hql);
String url = ""; //记录提示信息
if(!list.isEmpty()){
AdminInfo ai = list.get(0);
url = "/index.jsp";
session.setAttribute("admin",aname); //将管理员名存入session
session.setAttribute("alevel",ai.getAlevel()); //将管理员级别存入session
}
else{
String msg = "对不起,登陆失败!!!";
request.setAttribute("msg",msg); //将错误信息添加到请求中
url = "/info.jsp";
}
ServletContext sc = getServletContext(); //得到上下文
RequestDispatcher rd = sc.getRequestDispatcher(url);
rd.forward(request,response); //页面跳转
}
else if(action.equals("logout")){ //当管理员注销时
request.getSession(true).invalidate(); //使session失效
response.sendRedirect("adminlogin.jsp"); //页面跳转
}求大神指教,在做一个进销存管理系统,菜鸟一个呀
解决方案
您的33行驶哪一行呢?这边看不大清楚
解决方案二:
你dopost 方法有空指针报错了。
解决方案三:
报的空指针异常,你debug一下看看是不是前台页面输入的用户名和密码的值,没有传到后台,所以报空指针异常