求教jsp中javabean的使用
我想做个注册的页面,调用javabean写进数据库。并在成功后显示用户名和密码 但是总是在运行时抱错!都郁闷我两天了 以下是代码 请高手指教
////userbean.java
import java.sql.*;
public class userbean
{
private String username=null;
private String password=null;
public userbean()
{
}
public void setUsername(String username)
{
this.username=username;
}
public void setPassword(String password)
{
this.password=password;
}
public String getUsername()
{
return this.username;
}
public String getPassword()
{
return this.password;
}
public String insert()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection dbcon=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=fight;","sa","");
PreparedStatement stat=dbcon.prepareStatement("insert login values(?,?)");
stat.setString(1,username);
stat.setString(2,password);
stat.executeUpdate();
return "success";
}
catch(Exception e)
{
System.out.println(e);
return e.toString();
}
}
}
////login.jsp
<html>
<center>
<form method=post action="test1.jsp">
username<input type=text name=username>
<br><br>
password<input type=password name=password>
<br><br>
<input type=submit value="注册">
</form>
</center>
</html>
//////////////test1.jsp
<%@ page contentType="text/html;charset=GB2312" language="java" %>
<html>
<jsp:useBean id="hello" class="userbean" scope="session" />
<jsp:setProperty name="hello" property="*" />
your username is:<jsp:getProperty name="hello" property="username"/>
<br><br>
your password is:<jsp:getProperty name="hello" property="password"/>
<br><br>
</html>
运行时抱错,说我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: Unable to compile class for JSP
An error occurred at line: 4 in the jsp file: /test1.jsp
Generated servlet error:
C:\jakarta-tomcat-5.0.27\work\Catalina\localhost\aiai\org\apache\jsp\test1_jsp.java:45: cannot resolve symbol
symbol : class userbean
location: class org.apache.jsp.test1_jsp
userbean hello = null;
^
An error occurred at line: 4 in the jsp file: /test1.jsp
Generated servlet error:
C:\jakarta-tomcat-5.0.27\work\Catalina\localhost\aiai\org\apache\jsp\test1_jsp.java:47: cannot resolve symbol
symbol : class userbean
location: class org.apache.jsp.test1_jsp
hello = (userbean) _jspx_page_context.getAttribute("hello", PageContext.SESSION_SCOPE);
^
An error occurred at line: 4 in the jsp file: /test1.jsp
Generated servlet error:
C:\jakarta-tomcat-5.0.27\work\Catalina\localhost\aiai\org\apache\jsp\test1_jsp.java:49: cannot resolve symbol
symbol : class userbean
location: class org.apache.jsp.test1_jsp
hello = new userbean();
^
An error occurred at line: 8 in the jsp file: /test1.jsp
Generated servlet error:
C:\jakarta-tomcat-5.0.27\work\Catalina\localhost\aiai\org\apache\jsp\test1_jsp.java:59: cannot resolve symbol
symbol : class userbean
location: class org.apache.jsp.test1_jsp
out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((userbean)_jspx_page_context.findAttribute("hello")).getUsername())));
^
An error occurred at line: 12 in the jsp file: /test1.jsp
Generated servlet error:
C:\jakarta-tomcat-5.0.27\work\Catalina\localhost\aiai\org\apache\jsp\test1_jsp.java:65: cannot resolve symbol
symbol : class userbean
location: class org.apache.jsp.test1_jsp
out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((userbean)_jspx_page_context.findAttribute("hello")).getPassword())));
^
5 errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.27
求教大虾指教啊!!!!