JSP中调用java中的方法-最后一句会出错 请指教
package com.yuu.www;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.*;
public class SecretImport extends HttpServlet {
public void doGet(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException{
process(req,resp);
}
protected void doPost(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException {
process(req,resp);
}
private void process(HttpServletRequest req,HttpServletResponse resp)
throws IOException{
try{
String username = req.getParameter("username");
String password=req.getParameter("password");
System.out.print(username);
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<html><head><title>Login</title></head>");
out.println("<body>username:"+username+"<br>");
out.println("password:"+password+"</body></html>");
out.flush();}
catch(Exception e){e.printStackTrace();}
}
}
class DbConnect {
private Connection dbconn;
private Statement dbstate;
private ResultSet dbresult;
DbConnect(){
dbconn = null;
dbstate = null;
dbresult = null;
}
public void print(String str){
System.out.println(str);
}
//连接Mysql数据库
public boolean dbConnection(String host,String port,String dbaName,String usName,String psw){
String driverName = "org.git.mm.mysql.Driver";
String dbHost = host;// 数据库的一些信息
String dbPort = port;
String dbName = dbaName;
String enCoding = "?useUnicode=true&characterEncoding=gb2312"; //解决MYSQL中文问题,要连续写 不能有空格
String userName = usName;
String Psw = psw;
String url = "jdbc:mysql://"+dbHost+":"+dbPort+"/"+dbName+enCoding;
try
{
Class.forName(driverName).newInstance();
dbconn = DriverManager.getConnection(url,userName,Psw);
//getConnection(url, userName, Psw)从给的driver中选择合适的去连接数据库
//return a connectiong to the URl
} catch (Exception e){
print("url="+url);//发生错误时,将连接数据库信息打印出来
print("userName="+userName);
print("Psw="+Psw);
print("Exception:"+e.getMessage());//得到出错信息
}
if (dbconn != null)//dbconn!=null表示连接数据库成功
return true;
else
return false;
}
//对数据表中的记录进行删除操作
public boolean dbDelete (String tableName,String condition)
{
boolean delResult = false;
String sql = "delete from "+tableName+""+condition;
try{
dbstate.executeUpdate(sql);
delResult = true;
}catch(Exception e){
print("sql= "+sql);
print("Exception:"+e.getMessage());
}
if(delResult)
return true;
else
return false;
}
}
/////////////////////////////////////////////JSP
<%@page contentType="text/html;charset=gb2312" %>
<%@page import="java.sql.*"%>
<%@page import="com.yuu.www.*"%>
<% dbDelete dbc = new dbDelete();%> 这边会出错!!!!!为什么呢 ??