标题:[求助]jsp初学:关于JSP+servlet的问题请都大家,急!!
取消只看楼主
zhangkangl
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-11-25
 问题点数:0 回复次数:2 
[求助]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>
搜索更多相关主题的帖子: jsp servlet JSP 初学 jasper 
2007-11-25 17:45
zhangkangl
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-11-25
得分:0 
我的LoginBean就是放在bean包里面的呀,错在哪里呀
2007-11-27 16:12
zhangkangl
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-11-25
得分:0 
我做了一些改正,现在的情况是出现了登录对话框,输入用户名和密码后又出现了以下的错误提示
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 problems:
 Syntax error on token "Invalid Character", ; expected
 Syntax error on token "Invalid Character", ; expected
 servlet.LoginServlet.doPost(LoginServlet.java:47)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
2007-11-29 06:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-188298-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.189931 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved