我用JB2005,TOMCAT,MSSQL创建简单的修改数据库页面,通过creat.jsp传递表单值到switch.jsp,然后通过user.java自动获取,代码如下:
creat.jsp
<%@ page contentType="text/html; charset=GBK" %>
<meta http-equiv="refresh" content=120>
<html>
<head>
<title>
creat
</title>
</head>
<form name="form1" method="post" action="switch.jsp">
<input type="text" name="ID" value="ID">
<input type="text" name="PS" value="PASSWORD">
<input type="submit" name="Submit" value="提交">
</form>
<body bgcolor="#ffffff">
</body>
</html>
switch.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%@page import="java.sql.*"%>
<jsp:useBean id="insert" class="insert.user" scope="page" />
<jsp:setProperty name="insert" property="*" />
<%
String driver= "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=master";
String user="sa";
String passw="sa";
String userId=Bean.getUserId();
String password=Bean.getPassword();
String sql="insert into data(ID,PS) values('"+userId+"','"+password+"')";
Statement stmt;
Connection con;
try{
Class.forName(driver);
con = DriverManager.getConnection(url,user,passw);
stmt=con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
con.close();
}
catch(ClassNotFoundException e){
System.out.println(e.getMessage());
}
catch(SQLException e){
System.out.println(e.getMessage());
}
%>
user.java
package insert;
public class user {
public user(){}
private String ID;
private String PS;
public String getPassword() {
return PS;
}
public String getUserId() {
return ID;
}
public void setPassword(String PS) {
this.PS = PS;
}
public void setUserId(String ID) {
this.ID = ID;
}
}
不知道为什么,调试时,IE总是出现这样的错误:
org.apache.jasper.JasperException: /insert/WebModule1/switch.jsp(3,0) The value for the useBean class attribute insert.user is invalid.
难道我的user.java错了吗?希望各位帮帮忙!
creat.jsp
<%@ page contentType="text/html; charset=GBK" %>
<meta http-equiv="refresh" content=120>
<html>
<head>
<title>
creat
</title>
</head>
<form name="form1" method="post" action="switch.jsp">
<input type="text" name="ID" value="ID">
<input type="text" name="PS" value="PASSWORD">
<input type="submit" name="Submit" value="提交">
</form>
<body bgcolor="#ffffff">
</body>
</html>
switch.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%@page import="java.sql.*"%>
<jsp:useBean id="insert" class="insert.user" scope="page" />
<jsp:setProperty name="insert" property="*" />
<%
String driver= "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=master";
String user="sa";
String passw="sa";
String userId=Bean.getUserId();
String password=Bean.getPassword();
String sql="insert into data(ID,PS) values('"+userId+"','"+password+"')";
Statement stmt;
Connection con;
try{
Class.forName(driver);
con = DriverManager.getConnection(url,user,passw);
stmt=con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
con.close();
}
catch(ClassNotFoundException e){
System.out.println(e.getMessage());
}
catch(SQLException e){
System.out.println(e.getMessage());
}
%>
user.java
package insert;
public class user {
public user(){}
private String ID;
private String PS;
public String getPassword() {
return PS;
}
public String getUserId() {
return ID;
}
public void setPassword(String PS) {
this.PS = PS;
}
public void setUserId(String ID) {
this.ID = ID;
}
}
不知道为什么,调试时,IE总是出现这样的错误:
org.apache.jasper.JasperException: /insert/WebModule1/switch.jsp(3,0) The value for the useBean class attribute insert.user is invalid.
难道我的user.java错了吗?希望各位帮帮忙!
第二 你的jsp名字不要用switch 你很喜欢用一些关键字或者特殊作为名字很不好。我认为如果你的数据库连接没问题的话就可以了!!!
org.apache.jasper.JasperException: /insert/WebModule1/switch.jsp(3,0) The value for the useBean class attribute insert.user is invalid.
package insert;
public class user {
public user(){}
private String id;
private String ps;
public String getPs() {
return PS;
}
public String getId() {
return id;
}
public void setPs(String PS) {
ps = PS;
}
public void setId(String ID) {
id = ID;
}
}
看看bean的定义规则
-----------------------------
问题我想是这里了
如果你的userID是数字型的话就不要双引号
而是单引号.检查你的数据类型试试