严重: Servlet.service() for servlet LoginServlet threw exception
packagesunyang.controller;importjava.io.IOException;importjavax.servlet.*;importjavax...
package sunyang.controller;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import sunyang.domain.User;
import sunyang.service.UserService;
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String username=req.getParameter("username");
//System.out.println("000001"+username);
String userpsw=req.getParameter("usepsw");
User user=new User();
user.setUsername(username);
user.setUserpsw(userpsw);
//System.out.println("000000000004"+user.getUsername());
HttpSession session=req.getSession();
String forward="";
if(UserService.CheckLogin(user)){
forward="success.jsp";
session.setAttribute("name", username);
//System.out.println("0000000002"+user);
String username1=(String)session.getAttribute("name");
//System.out.println("000000000003"+username1);
}else{
forward="error.jsp";
}
RequestDispatcher rd =req.getRequestDispatcher(forward);
rd.forward(req, resp);
}
}
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>sunyang.controller.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>
空指针异常,可是小弟我没有找到错啊。。。求大神解脱啊!!
<body>
<form action="login" method="post">
用户名称:<input type="text" name="username" value="" ><br>
用户密码:<input type="password" name="userpwd" value=""><br>
<input type="submit" name="submit" value="登录"/>
<input type="reset" name="reset" value="重写"/>
</form>
</body>
</html> 展开
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import sunyang.domain.User;
import sunyang.service.UserService;
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String username=req.getParameter("username");
//System.out.println("000001"+username);
String userpsw=req.getParameter("usepsw");
User user=new User();
user.setUsername(username);
user.setUserpsw(userpsw);
//System.out.println("000000000004"+user.getUsername());
HttpSession session=req.getSession();
String forward="";
if(UserService.CheckLogin(user)){
forward="success.jsp";
session.setAttribute("name", username);
//System.out.println("0000000002"+user);
String username1=(String)session.getAttribute("name");
//System.out.println("000000000003"+username1);
}else{
forward="error.jsp";
}
RequestDispatcher rd =req.getRequestDispatcher(forward);
rd.forward(req, resp);
}
}
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>sunyang.controller.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>
空指针异常,可是小弟我没有找到错啊。。。求大神解脱啊!!
<body>
<form action="login" method="post">
用户名称:<input type="text" name="username" value="" ><br>
用户密码:<input type="password" name="userpwd" value=""><br>
<input type="submit" name="submit" value="登录"/>
<input type="reset" name="reset" value="重写"/>
</form>
</body>
</html> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询