yangtingsky
yangtingsky
2017-04-03 23:01
采纳率: 71.4%
浏览 1.6k
已采纳

浏览器取不到后台传过来的数据

后台传参代码:

public class LoginAction extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try{
String uname=req.getParameter("uname");
String upass=req.getParameter("upass");
//service帮助验证

                UserService us=new UserService();
                User user=us.checkLogin(uname, upass);

                if(user==null){
                    resp.sendRedirect("login.jsp?f=9");

                }else{
                     req.getSession().setAttribute("currentUser", user);
                     resp.sendRedirect("main.jsp");
                }

                }catch(Exception e){
                    e.printStackTrace();
                }
    }

}

浏览器端接收参数代码:

运行程序,前面都 正常运行,到了浏览器却报空指针错误,取不到参数f的值
什么原因?

错误日志:

严重: Servlet.service() for servlet jsp threw exception

java.lang.NullPointerException
at org.apache.jsp.login_jsp._jspService(login_jsp.java:68)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
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:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
null

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • com_it
    青鸟路过佳城 2017-04-04 00:01
    已采纳

    重定向要加上斜杠和项目名 resp.sendRedirect(/项目名/...)

    点赞 评论
  • miaoch
    miaoch 2017-04-04 02:35

    if(user==null){
    resp.sendRedirect("login.jsp?f=9");

                }else{
                     req.getSession().setAttribute("currentUser", user);
                     resp.sendRedirect("main.jsp");
                }
                                首先你的写法是user==null 才传f=9;另外你是怎么获取f的 最好也列出来
    
    点赞 评论

相关推荐