2 xiaokangtongxue410 xiaokangtongxue410 于 2016.03.09 20:42 提问

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"); //页面跳转
}

求大神指教,在做一个进销存管理系统,菜鸟一个呀

这里是对应的代码段

3个回答

qq_21912927
qq_21912927   2016.03.09 21:23

您的33行驶哪一行呢?这边看不大清楚

xiaokangtongxue410
xiaokangtongxue410 您好,代码段的行数在上图中
接近 2 年之前 回复
rui888
rui888   Ds   Rxr 2016.03.10 10:00

你dopost 方法有空指针报错了。

qq_30408111
qq_30408111   2016.03.10 13:56

报的空指针异常,你debug一下看看是不是前台页面输入的用户名和密码的值,没有传到后台,所以报空指针异常

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!