javaBean.java代码如下
package newd;
import java.sql.*;
public class conndb {
String url="jdbc:odbc:new_db";//链接系统DSN
Connection conn=null;//建立连接对象
Statement st;
PreparedStatement stmt=null;
ResultSet rs;
public conndb(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//告诉程序使用JDBC-ODBC创建数据库连接
conn = DriverManager.getConnection(url,"","");
}
catch(Exception e){
e.printStackTrace();
}
}
public ResultSet executeQuery(String sql)throws Exception{
try{
this.stmt=null;
this.stmt=conn.prepareStatement(sql);
return this.stmt.executeQuery();
}
catch(SQLException e){
e.printStackTrace();
return null;
}
}
public int excuteUpdata(String sql)throws Exception{
try{
this.stmt=null;
this.stmt=conn.prepareStatement(sql);
return this.stmt.executeUpdate();
}
catch (SQLException e){
e.printStackTrace();
return 0;
}
}
public void closedb(){
try{
conn.close();
stmt.cancel();
}
catch(Exception e){
e.printStackTrace();
}
}
}应用网页代码如下
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="error.jsp" %>
<jsp:useBean id="db" scope="application" class="newd.conndb"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册成功</title>
<style type="text/css">
<!--
body,td,th {
font-family: 宋体;
}
body {
background-color: #FFFF00;
}
-->
</style></head>
<body>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center"> </h1><%
String name=request.getParameter("usename");
String pwd=request.getParameter("psw");
String pwd1=request.getParameter("psw1");
String xbie=request.getParameter("xbie");
if(pwd!=pwd1||name==null||name.equals("")||pwd.equals("")){
session.setAttribute("error","1");
response.sendRedirect("error.jsp");
}
else if(xbie==null||xbie.equals("")){
session.setAttribute("error","2");
response.sendRedirect("error.jsp");
}
else {
try{
String sql="select name from zhuce";
ResultSet rs=db.executeQuery(sql);
if(rs.next()){
session.setAttribute("error","3");
response.sendRedirect("error.jsp");
}
}
}
%>
<h1 align="center">------------恭喜您注册成功------------</h1>
<h2 align="center"><a href="index.jsp">点击这里登录!</a></h2>
</body>
错误代码如下
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: /JSP/JSPok.jsp(2,0) The value for the useBean class attribute newd.conndb is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1200)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1155)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2386)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2392)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Generator.generate(Generator.java:3394)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:210)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.10
帮助一下,这是什么原因
package newd;
import java.sql.*;
public class conndb {
String url="jdbc:odbc:new_db";//链接系统DSN
Connection conn=null;//建立连接对象
Statement st;
PreparedStatement stmt=null;
ResultSet rs;
public conndb(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//告诉程序使用JDBC-ODBC创建数据库连接
conn = DriverManager.getConnection(url,"","");
}
catch(Exception e){
e.printStackTrace();
}
}
public ResultSet executeQuery(String sql)throws Exception{
try{
this.stmt=null;
this.stmt=conn.prepareStatement(sql);
return this.stmt.executeQuery();
}
catch(SQLException e){
e.printStackTrace();
return null;
}
}
public int excuteUpdata(String sql)throws Exception{
try{
this.stmt=null;
this.stmt=conn.prepareStatement(sql);
return this.stmt.executeUpdate();
}
catch (SQLException e){
e.printStackTrace();
return 0;
}
}
public void closedb(){
try{
conn.close();
stmt.cancel();
}
catch(Exception e){
e.printStackTrace();
}
}
}应用网页代码如下
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="error.jsp" %>
<jsp:useBean id="db" scope="application" class="newd.conndb"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册成功</title>
<style type="text/css">
<!--
body,td,th {
font-family: 宋体;
}
body {
background-color: #FFFF00;
}
-->
</style></head>
<body>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center"> </h1><%
String name=request.getParameter("usename");
String pwd=request.getParameter("psw");
String pwd1=request.getParameter("psw1");
String xbie=request.getParameter("xbie");
if(pwd!=pwd1||name==null||name.equals("")||pwd.equals("")){
session.setAttribute("error","1");
response.sendRedirect("error.jsp");
}
else if(xbie==null||xbie.equals("")){
session.setAttribute("error","2");
response.sendRedirect("error.jsp");
}
else {
try{
String sql="select name from zhuce";
ResultSet rs=db.executeQuery(sql);
if(rs.next()){
session.setAttribute("error","3");
response.sendRedirect("error.jsp");
}
}
}
%>
<h1 align="center">------------恭喜您注册成功------------</h1>
<h2 align="center"><a href="index.jsp">点击这里登录!</a></h2>
</body>
错误代码如下
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: /JSP/JSPok.jsp(2,0) The value for the useBean class attribute newd.conndb is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1200)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1155)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2386)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2392)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Generator.generate(Generator.java:3394)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:210)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.10
帮助一下,这是什么原因
这个有问题
......
知道这个是什么意思吗?
转换成java代码:newd.conndb db = (newd.conndb)application.getAttribute("");
是不是感觉少了点什么?你保存在application中的newd.conndb对象的名字是哪个?否则怎么可能找到。
你这句的目的是不是看看用户名称是否已经注册?那你为什么不加上查询条件?where name="+name+"
是不是感觉少了点什么?你保存在application中的newd.conndb对象的名字是哪个?否则怎么可能找到。”
其他的网页还没连接数据库测试,就连了这一个,jsp现在刚开始学,还不太懂您说的意思