高手帮帮我,关于jsp+bean的问题
高手帮帮我,关于jsp+bean的问题我在做一个jsp+bean连接数据查询时,出现以下错误,我是初学者,高手帮我看看
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: /copylogin.jsp(3,0) The value for the useBean class attribute moon.mybean.mybean is invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
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: /copylogin.jsp(3,0) The value for the useBean class attribute moon.mybean.mybean is invalid.
org.apache.(DefaultErrorHandler.java:39)
org.apache.(ErrorDispatcher.java:405)
org.apache.(ErrorDispatcher.java:146)
org.apache.(Generator.java:1174)
org.apache.(Node.java:1116)
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)
我猜想应该是bean无效的原因,可我不知道为什么bean无效,我的目录结构如下:
E:\J2ee\Tomcat 5.5\webapps\link{copylogin.jsp
E:\J2ee\Tomcat 5.5\webapps\link\WEB-INF\classes\moon\mybean\Mybean.class}
我的copylogin.jsp代码如下:
<%@ page c language="java" pageEncoding="GB18030"%>
<%@ page import="moon.mybean.Mybean" %>
<jsp:useBean id="login" class="moon.mybean.Mybean" scope="session"/>
<html>
<head>
<title>学生管理系统</title>
</head>
<body style="text-align:center">
<br/> <br/> <br/> <br/> <br/> <br/>
<jsp:setProperty name="login" property="*"/>
<form action="" method="post">
<table border="1">
<tr>
<th>用户登录</th>
</tr>
<tr>
<td>用户名 <input type=text name="loginname"></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>
Mybean.java代码如下:
package moon.mybean;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Mybean {
String loginname;
StringBuffer news=new StringBuffer();
String password;
public void setLoginname(String loginname){
this.loginname=loginname;
}
public String getLoginname(){
return loginname;
}
public void setPassword(String password){
this.password=password;
}
public StringBuffer getNews(){
try{Class.forName("com.microsort.jdbc.sqlserver.SQLServerDriver");
}
catch(Exception ee){}
Connection con;
PreparedStatement sql;
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();
con.close();
news.append("<table bord=1>");
while(rs.next()){
news.append("<tr>");
news.append("<td>"+rs.getString(1)+"</td>");
news.append("<td>"+rs.getString(2)+"</td>");
news.append("<td>"+rs.getString(3)+"</td>");
news.append("<td>"+rs.getString(4)+"</td>");
news.append("<td>"+rs.getString(5)+"</td>");
news.append("</tr>");
}
news.append("</table>");
}
catch(SQLException exp){}
return news;
}
}