jsp+mysql+java问题
user.javapackageBean;importcom.core.*;publicclassuser{privateStringname=null;privateS...
user.java
package Bean;
import com.core.*;
public class user {
private String name=null;
private String password=null;
private ConnDB conn1=null;
public void setname(String n){name=n;}
public void setpassword(String pass){password=pass;}
public String getname(){return name;}
public String getpassword(){return password;}
public int check(String n,String pass){
conn1=new ConnDB();
int i=conn1.CheckUser("belmaiastar", "000111");
return i;
}
}
LoginCheck.jsp
<%@ page contentType="text/html;charset=utf-8" %>
<%@ page language="java"%>
<html>
<title>check</title>
<jsp:useBean id="test" scope="page" class="Bean.user" />
<%String name="belmaiastar";
String password="000111";
out.print(test.check(name,password));%>
</html>
ConnDB.java
package com.core;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class ConnDB {
public Connection conn;
public PreparedStatement s;
public Statement r;
public String url,UserName,Password;
public ConnDB(){
conn=null;
url="jdbc:mysql://localhost/sbszp";
UserName="root";
Password="root";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection(url,UserName,Password);
//System.out.println("Connected!");
}
catch(Exception e){
//System.err.println("Cannot connect to server");
//System.exit(1);
}
}
public int InsertUser(String n,String pass){
try{
s=conn.prepareStatement("insert into user(name,password)"+"values(?,?)");
s.setString(1, n);
s.setString(2, pass);
int count=s.executeUpdate();
System.out.println(count);
s.close();
}
catch(SQLException ex){return 0;}
return 1;
}
public int CheckUser(String n,String pass){
try{
String result=null;
r=conn.createStatement();
r.executeQuery("select password from user where name="+"'"+n+"'");
ResultSet rs=r.getResultSet();
rs.next();
result=rs.getString(1);
if(result.equals(pass)) return 1;
else return 0;
}
catch(SQLException ex){return 0;}
}
}
用tomcat开服务器后报错,org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
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)
但用java se调试明明正确,跪求原因和解决方法。
test.javapackage Bean;
import Bean.user.*;
import java.io.*;
public class test {
public static void main(String[] args) {
user test=new user();
System.out.println(test.check("belmaiastar", "000111"));
}
}显示是1 展开
package Bean;
import com.core.*;
public class user {
private String name=null;
private String password=null;
private ConnDB conn1=null;
public void setname(String n){name=n;}
public void setpassword(String pass){password=pass;}
public String getname(){return name;}
public String getpassword(){return password;}
public int check(String n,String pass){
conn1=new ConnDB();
int i=conn1.CheckUser("belmaiastar", "000111");
return i;
}
}
LoginCheck.jsp
<%@ page contentType="text/html;charset=utf-8" %>
<%@ page language="java"%>
<html>
<title>check</title>
<jsp:useBean id="test" scope="page" class="Bean.user" />
<%String name="belmaiastar";
String password="000111";
out.print(test.check(name,password));%>
</html>
ConnDB.java
package com.core;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class ConnDB {
public Connection conn;
public PreparedStatement s;
public Statement r;
public String url,UserName,Password;
public ConnDB(){
conn=null;
url="jdbc:mysql://localhost/sbszp";
UserName="root";
Password="root";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection(url,UserName,Password);
//System.out.println("Connected!");
}
catch(Exception e){
//System.err.println("Cannot connect to server");
//System.exit(1);
}
}
public int InsertUser(String n,String pass){
try{
s=conn.prepareStatement("insert into user(name,password)"+"values(?,?)");
s.setString(1, n);
s.setString(2, pass);
int count=s.executeUpdate();
System.out.println(count);
s.close();
}
catch(SQLException ex){return 0;}
return 1;
}
public int CheckUser(String n,String pass){
try{
String result=null;
r=conn.createStatement();
r.executeQuery("select password from user where name="+"'"+n+"'");
ResultSet rs=r.getResultSet();
rs.next();
result=rs.getString(1);
if(result.equals(pass)) return 1;
else return 0;
}
catch(SQLException ex){return 0;}
}
}
用tomcat开服务器后报错,org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
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)
但用java se调试明明正确,跪求原因和解决方法。
test.javapackage Bean;
import Bean.user.*;
import java.io.*;
public class test {
public static void main(String[] args) {
user test=new user();
System.out.println(test.check("belmaiastar", "000111"));
}
}显示是1 展开
2010-05-07
展开全部
启动不出错,打开页面就myeclipse就显示服务器断开了。我无法追加提问,就这样说了
展开全部
根据报错,应该是JSP问题
关于jsp 好像不是用language="java" 吧
一般会默认用Java Script 所以没必要写 language
并且sun公司用的网页编程是 Java Script 而不是java吧
关于jsp 好像不是用language="java" 吧
一般会默认用Java Script 所以没必要写 language
并且sun公司用的网页编程是 Java Script 而不是java吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
url="jdbc:mysql://localhost/sbszp";
这个地方要加端口号吧?如果你没改应该是3306
这个地方要加端口号吧?如果你没改应该是3306
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是启动tomcat搞错啊 还是打开页面报错啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询