新手求助:为什么会报 HTTP Status 500?
HTTP Status 500 -
type Exception report
message

description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
org.cai.servlet.LoginServlet.doPost(LoginServlet.java:69)
javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.39 logs.
LoginServlet.java
package org.cai.servlet ;
import java.sql.* ;
import java.io.* ;
import javax.servlet.http.* ;
import javax.servlet.* ;
public class LoginServlet extends HttpServlet implements Servlet{
public LoginServlet(){
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
}
// protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
// System.out.println("-------------------------") ;
// doPost(request, response) ;
// }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
response.setContentType("text/html;charset=gb2312") ;
request.setCharacterEncoding("gb2312") ;
String result = "" ;
//获取用户名
String username = request.getParameter("username") ;
String psw = request.getParameter("password") ;
if ((username == "") || (username==null) || (username.length() > 20 )){
try{
result = "请输入用户名(不能超过20个字符)!" ;
request.setAttribute("message" ,result) ;
response.sendRedirect("login.jsp") ;
}catch(Exception e){
e.printStackTrace() ;
}
}
if ((psw == "") || (psw==null) || (psw.length() > 20 )){
try{
result = "请输入密码(不能超过20个字符)!" ;
request.setAttribute("message" ,result) ;
response.sendRedirect("login.jsp") ;
}catch(Exception e){
e.printStackTrace() ;
}
}
//登记JDBC驱动程序
try{
Class.forName("org.gjt.mm.mysql.Driver") ;
}catch(ClassNotFoundException e){
e.printStackTrace() ;
System.out.println("Class Not Found Exception . ") ;
}
//连接URL
String url ="jdbc:mysql://localhost:3306/learnJSP" ;
Connection conn = null ;
Statement stmt = null ;
ResultSet rs = null ;
try{
conn = DriverManager.getConnection(url, "root", "520") ;
stmt = conn.createStatement() ;
//SQL语句
String sql ="select * from userInfo where username='"+username+"' and userpsw= '"+psw+"'" ;
rs = stmt.executeQuery(sql) ;//返回查询结果
}catch(SQLException e){
e.printStackTrace() ;
}
HttpSession session = request.getSession() ;
session.setAttribute("username", username) ;
//System.out.println("+++++++++++++++++++++++"+ username) ;
try{
if (rs.next()){ //如果记录集非空,表明有匹配的用户名和密码,登陆成功
// 登录成功后将username设置为session变量的username
// 这样在后面就可以通过 session.getAttribute("username") 来获取用户名,
// 同时这样还可以作为用户登录与否的判断依据
session.setAttribute("age",rs.getString("age")) ;
session.setAttribute("sex",rs.getString("sex")) ;
session.setAttribute("weight",rs.getString("weight")) ;
response.sendRedirect("success.jsp") ;
}else{
session.setAttribute("message", "用户名或密码不匹配。");
response.sendRedirect("fail.jsp") ;
}
}catch(SQLException e){
e.printStackTrace() ;
}
}
private static final long serialVersionUID = 1L;
}
相关推荐
Tomcat报错:HTTP Status 500 (Wrapper cannot find servlet class)解决办法
主要介绍了Tomcat报错:HTTP Status 500 (Wrapper cannot find servlet class)解决办法的相关资料,需要的朋友可以参考下
SSM:HTTP Status 500 – Internal Server Error (原创)
SSM:HTTP Status 500 – Internal Server Error
request.setAttribute 语句前总显示红色感叹号解决办法 HTTP Status 500 -
HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet execution threw an exception root cause java.lang.Error: Unresolved compilation problem: The method setAttribute(String, Object) in the type ServletRequest is not applicable for the arguments (String, double) y2ssh.sg.chp1.action.AddAction.execute(AddAction.java:18) y2ssh.sg.chp1.framework.Controller.doGet(Controller.java:25) y2ssh.sg.chp1.framework.Controller.doPost(Controller.java:33) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)解决办法:
HTTP 500 服务器内部错误的解决方法
IIS500错误,是因为微软的一个BUG所造成的。下面是解决办法: 主要是由于IWAM账号(在我的计算机即是IWAM_MYSERVER账号)的密码错误造成了HTTP 500内部错误。 在详细分析HTTP500内部错误产生的 ...
Tomcat 5.5.26 Administration Tool HTTP Status 500 临时解决
用于解决使用 Tomcat 5.5.26 Administration Tool 的 Delete Existing Hosts 功能时发生 HTTP Status 500 错误,详见 http://blog.csdn.net/LaoBai_2006/archive/2008/08/28/2844042.aspx。 md5: f8ad905990a96f0016682ffd28014701


