如何把jsp文件里的java代码写到java文件中封装起来,这两个文件要改成什么样?
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"import...
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>
<body>
<%
String searchStr="";
if(request.getParameter("keyValue")!=null){
String keyField=request.getParameter("keyField");
String keyValue=new String(request.getParameter("keyValue").getBytes("iso8859-1"),"utf-8");
searchStr="where "+keyField+" like '%"+keyValue+"%'";
}
String driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=Center_CB";
String user = "SqlConnect"; String password = "123456";Connection con =null;Statement st=null;
ResultSet rs=null;
try{ Class.forName(driverClass);
con=DriverManager.getConnection(url, user, password);
st=con.createStatement();
}catch(Exception e) { e.printStackTrace(System.err); out.println("网站出错,请与管理员联系"); return;}
%>
<Div id="searchDiv"> <form method="post" name="search"> 按<select name="keyField"><option value="User_No" selected>户号</option><option value="phone">电话号码</option></select>
关键字<input type="text" name="keyValue"/><input type="submit" name="submit" value="搜索"> </form> </Div> 展开
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>
<body>
<%
String searchStr="";
if(request.getParameter("keyValue")!=null){
String keyField=request.getParameter("keyField");
String keyValue=new String(request.getParameter("keyValue").getBytes("iso8859-1"),"utf-8");
searchStr="where "+keyField+" like '%"+keyValue+"%'";
}
String driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=Center_CB";
String user = "SqlConnect"; String password = "123456";Connection con =null;Statement st=null;
ResultSet rs=null;
try{ Class.forName(driverClass);
con=DriverManager.getConnection(url, user, password);
st=con.createStatement();
}catch(Exception e) { e.printStackTrace(System.err); out.println("网站出错,请与管理员联系"); return;}
%>
<Div id="searchDiv"> <form method="post" name="search"> 按<select name="keyField"><option value="User_No" selected>户号</option><option value="phone">电话号码</option></select>
关键字<input type="text" name="keyValue"/><input type="submit" name="submit" value="搜索"> </form> </Div> 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询