求助!关于JavaBean 问题

frankgoahead 2010-05-15 05:29:33
今天写一个小小的jsp登陆程序,使用JavaBean时不能运行,麻烦各位帮忙看一下
错误提示:The value for the useBean class attribute User is invalid.
希望大家给一些解决办法,也可以加QQ联系 QQ:1079639410

Java 程序

package user;
import java.sql.*;
public class User {
private String username;
private String password;
private byte permit=0;


Connection conn=null;
Statement stmt;
String url="jdbc:mysql://localhost/log";
String sql1="insert into user"+"values('',username,password,permit)";
String sql2="select * from user";

public User(String username, String password, byte permit) {
super();
this.username = username;
this.password = password;
this.permit = permit;
}
public void selectElements(){
try {
Class.forName("com.mysql.jdbc.Driver");

} catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
System.out.println("类加载是出现异常");
}
try {
conn=DriverManager.getConnection(url);
stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql2);
while(rs.next()){
username=rs.getString(2);
password=rs.getString(3);
permit=rs.getByte(4);

}
stmt.close();
conn.close();

} catch (SQLException e) {

System.out.println("连接数据库出现异常");
}
}
public void insertElements(){
try {
Class.forName("com.mysql.jdbc.Driver");

} catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
System.out.println("类加载是出现异常");
}
try {
conn=DriverManager.getConnection(url);
stmt=conn.createStatement();
int row=stmt.executeUpdate(sql1);
stmt.close();
conn.close();

} catch (SQLException e) {

System.out.println("连接数据库出现异常");
}

}
public String getPassword() {
return password;
}
/**
* @param password 要设置的 password
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return permit
*/
public byte getPermit() {
return permit;
}
/**
* @param permit 要设置的 permit
*/
public void setPermit(byte permit) {
this.permit = permit;
}
/**
* @return username
*/
public String getUsername() {
return username;
}
/**
* @param username 要设置的 username
*/
public void setUsername(String username) {
this.username = username;
}


}

jsp程序

login.jsp
<%@ page language="java" contentType="text/html; charset=gb2312" import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function
</script>
</head>
<center>
<h2>登陆</h2>
<form method=post action="Check.jsp">
<table>
<tr>
<td>用户名:</td>
<td><input type=text name=username></td>
</tr>
<tr>
<td>密  码:</td>
<td><input type=password name=password></td>
</tr>
<tr>
<td>验证码:</td>
<td><input type=text name="rand" Maxlength='4' value="" size="6">
<img border=0 src="Image.jsp"> </td>
</tr>
</table>
<input type=submit value="登陆">
<input type=button value="注册" onClick="register.jsp">


</form>

</center>

</html>

Check.jsp
<%@ page import="user.User" contentType="text/html; charset=gb2312" %>
<jsp:useBean id="user1" class="User" scope="session">
</jsp:useBean>


<html>
<head>
<%
String username=request.getParameter("username");
String password=request.getParameter("password");
String rand=request.getParameter("rand");
if(rand==session.getAttribute("rand")){
user1.selectElements();
if(username==user1.getUsername()&&password==user1.getPassword()){
out.print("你已经登陆!你的权限是:"+user1.getPermit());
}
}
else{
out.print("验证码错误");
}


%>
<title>hgjk</title>
</head>
<body>
<% %>
</body>
</html>
Image.jsp

<%@ page contentType="image/jpeg" import="java.awt.*,
java.awt.image.*,java.util.*,javax.imageio.*" %>
<%!
Color getRandColor(int fc,int bc){
Random random = new Random();
if(fc>255) fc=255;
if(bc>255) bc=255;
int r=fc+random.nextInt(bc-fc);
int g=fc+random.nextInt(bc-fc);
int b=fc+random.nextInt(bc-fc);
return new Color(r,g,b);
}
%>
<%

response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);


int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);


Graphics g = image.getGraphics();


Random random = new Random();


g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);


g.setFont(new Font("Times New Roman",Font.PLAIN,18));





g.setColor(getRandColor(160,200));
for (int i=0;i<155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}


String sRand="";
for (int i=0;i<4;i++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;

g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));

g.drawString(rand,13*i+6,16);
}

session.setAttribute("rand",sRand);


g.dispose();


ImageIO.write(image, "JPEG", response.getOutputStream());
%>
...全文
128 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
frankgoahead 2010-05-15
  • 打赏
  • 举报
回复
我感觉这个程序没错啊
shichao2008 2010-05-15
  • 打赏
  • 举报
回复
user是无效的
iwantajia 2010-05-15
  • 打赏
  • 举报
回复
如果现在还没有解决加我的qq757966892我可以帮你看看
tfish2014 2010-05-15
  • 打赏
  • 举报
回复
贴错误信息和错误的那个页面代码足矣
验证码贴出来会害死人的 看着头晕
frankgoahead 2010-05-15
  • 打赏
  • 举报
回复
由于jsp程序做过一些测试有不严谨的地方希望大家见谅

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧