| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1321 人关注过本帖
标题:[求助]jsp初学:关于JSP+servlet的问题请都大家,急!!
只看楼主 加入收藏
zhangkangl
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-11-25
收藏
 问题点数:0 回复次数:6 
[求助]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
无缘今生
Rank: 2
等 级:新手上路
威 望:3
帖 子:523
专家分:7
注 册:2007-6-25
收藏
得分:0 
<url-pattern>/loginservlet</url-pattern>

你把web.xml中的那一行改成上面这行试试.

时不再来!!!
2007-11-25 21:20
suncf1985
Rank: 2
等 级:论坛游民
威 望:1
帖 子:158
专家分:35
注 册:2007-10-11
收藏
得分:0 
好像是那个包倒错了(jsp)页面中的

以后:独自享受着快乐、品味着孤独、体会着没有回忆的回忆....
2007-11-27 08:16
zhangkangl
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-11-25
收藏
得分:0 
我的LoginBean就是放在bean包里面的呀,错在哪里呀
2007-11-27 16:12
风月_无边
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:60
帖 子:2960
专家分:652
注 册:2007-1-19
收藏
得分:0 
應該是你的javabean位置不對或是沒有配置正確。好好檢查下

我的网站 http://www.
2007-11-27 18:08
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
tblovecj
Rank: 1
等 级:新手上路
帖 子:181
专家分:0
注 册:2006-9-20
收藏
得分:0 
你数据库操作用预处理那里,在用x.setString("",""),这里面的第一个参数表示第一个问号,应该是以0来表示第一个,改下试试

2007-11-30 18:16
快速回复:[求助]jsp初学:关于JSP+servlet的问题请都大家,急!!
数据加载中...
 
   



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

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