[求助]jsp初学:关于JSP+servlet的问题请都大家,急!!
[求助]jsp初学:关于JSP+servlet的问题请都大家,急!!jsp初学:关于JSP+servlet的问题请都大家,急!!
我初学jsp尝试做了一个jsp+servlet+bean的小程序,可怎么调都通不过,高手帮我看看,运行login.jsp出现下而问题
HTTP Status 500 - type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception org.apache.jasper.JasperException: bean.LoginBean org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:453) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause org.apache.jasper.JasperException: bean.LoginBean org.apache.(BeanRepository.java:77) org.apache.(Generator.java:1009) org.apache.(Node.java:1062) org.apache.(Node.java:2163) org.apache.(Node.java:2213) org.apache.(Node.java:2219) org.apache.(Node.java:456) org.apache.(Node.java:2163) org.apache.(Generator.java:3305) org.apache.(Compiler.java:198) org.apache.(Compiler.java:295) org.apache.(Compiler.java:276) org.apache.(Compiler.java:264) org.apache.jasper.(JspCompilationContext.java:563) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.lang.ClassNotFoundException: bean.LoginBean org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1352) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198) org.apache.(BeanRepository.java:75) org.apache.(Generator.java:1009) org.apache.(Node.java:1062) org.apache.(Node.java:2163) org.apache.(Node.java:2213) org.apache.(Node.java:2219) org.apache.(Node.java:456) org.apache.(Node.java:2163) org.apache.(Generator.java:3305) org.apache.(Compiler.java:198) org.apache.(Compiler.java:295) org.apache.(Compiler.java:276) org.apache.(Compiler.java:264) org.apache.jasper.(JspCompilationContext.java:563) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
Apache Tomcat/5.5.17我的login.jsp代码如下:
<%@ page c language="java" pageEncoding="GB18030"%>
<%@ page import="bean.*"%>
<jsp:useBean id="login" type="bean.LoginBean" scope="session"/>
<html>
<head>
<title>学生管理系统</title>
</head>
<body style="text-align:center">
<br/> <br/> <br/> <br/> <br/> <br/>
<form action="loginservlet" method="post">
<table border="1">
<tr>
<th>用户登录</th>
</tr>
<tr>
<td>用户名 <input type=text name="username"></td>
</tr>
<tr>
<td>密 码 <input type=password name="password"></td>
</tr>
</table>
<input type=submit name="submit" value="确定">
</form>
<jsp:getProperty name="login" property="news"/>
</body>
</html>
LoginServlet.java代码如下:
package servlet;
import *;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import bean.*;
public class LoginServlet extends HttpServlet{
public void init(ServletConfig config)throws ServletException{
super.init(config);
try{Class.forName("com.microsort.sqlserver.jdbc.SQLServerDriver");
}
catch(Exception ee){}
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
Connection con;
PreparedStatement sql;
String news="";
LoginBean login;
HttpSession session=request.getSession(true);
try{login=(LoginBean)session.getAttribute("login");
if(login==null){
login=new LoginBean();
session.setAttribute("login", login);
}
}
catch(Exception ee){
login=new LoginBean();
session.setAttribute("login", login);
}
String loginname=request.getParameter("username").trim();
String password=request.getParameter("password").trim();
if (loginname.length()>0){
try{String uri="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=studentmanagement";
con=DriverManager.getConnection(uri,"sa","sa");
sql=con.prepareStatement("select * from usertable where 用户名=?and密码=?");
sql.setString(1,loginname);
sql.setString(2, password);
ResultSet rs=sql.executeQuery();
boolean m=rs.next();
if (m==true){
login.setLoginname(loginname);
RequestDispatcher dispatcher=request.getRequestDispatcher("index.jsp");
dispatcher.forward(request, response);
}
else
{news="你输入的用户名不存在,或密码不正确";
login.setNews(news);
}
con.close();
}
catch(SQLException exp){}
}
else
{news="你输入的用户名不存在,或密码不正确";
login.setNews(news);
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
LoginBean代码如下:
package bean;
public class LoginBean {
String loginname;
String news;
public void setLoginname(String loginname){
this.loginname=loginname;
}
public String getLoginname(){
return loginname;
}
public void setNews(String news){
this.news=news;
}
public String getNews(){
return news;
}
}
web.xml代码如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<servlet-class>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>servlet.LoginServlet </servlet-class>
</servlet-class>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>loginservlet</url-pattern>
</servlet-mapping>
</web-app>