?? infoaction.java~13~
字號:
package wkhTest;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
import java.io.PrintWriter;
import java.sql.*;
public class InfoAction extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest servletRequest,
HttpServletResponse servletResponse) throws Exception{
InfoForm infoForm = (InfoForm) actionForm;
if(infoForm.getAction().equals("ShowInfo")){
servletRequest.setAttribute("Info",infoForm);
return actionMapping.findForward("ShowInfo");
}
else if(infoForm.getAction().equals("GetData_P")){
PrintWriter out = servletResponse.getWriter();
String strTemp="<%@ page contentType='text/html;charset=gb2312'%>";
String typing = infoForm.getName();
//連數據庫
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").
newInstance();
String url =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=portal";
String user = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql =
"select * from P_areacode where id like '%0000' and jp like '" +
typing + "%' ";
if (typing.equals("") || typing.equals(" ")) {
sql = "select * from P_areacode where id like '%0000' ";
}
ResultSet rs = stmt.executeQuery(sql);
String area = "";
String no = "";
while (rs.next()) {
area = rs.getString("area");
no = rs.getString("id");
no = no.substring(0, 2);
System.out.println("area="+area);
System.out.println("id="+no);
strTemp+="<div onselect='this.text.value = '"+toChinese(area)+"';$('PID').value = '"+no+"';$('Pold').value = '"+toChinese(area)+"';$('CID').value = '000000';$('city').value = '';$('AID').value = '000000';$('area').value = '';'><span class='informal'>No."+no+"</span>"+toChinese(area)+"</div>";
}
rs.close();
stmt.close();
conn.close();
out.write(strTemp);
return null;
}
else if(infoForm.getAction().equals("GetData_C")){
PrintWriter out = servletResponse.getWriter();
String strTemp="<%@ page contentType='text/html;charset=gb2312'%>";
String typing = infoForm.getName();
String PID = infoForm.getMail();
//連數據庫
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").
newInstance();
String url =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=portal";
String user = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select * from P_areacode where id like '" + PID +
"%00' and id!=" + PID + "0000" + " and jp like '" +
typing + "%' ";
if (typing.equals("") || typing.equals(" ")) {
sql = "select * from P_areacode where id like '" + PID +
"%00' and id!=" + PID + "0000 ";
}
ResultSet rs = stmt.executeQuery(sql);
String area = "";
String no = "";
while (rs.next()) {
area=rs.getString("area");
no=rs.getString("id");
no=no.substring(0,4);
strTemp+="<div onselect='this.text.value = '"+area+"';$('CID').value = '"+no+"';$('Cold').value = '"+area+"';$('AID').value = '000000';$('area').value = '';'><span class='informal'>No."+no+"</span>"+area+"</div>";
}
rs.close();
stmt.close();
conn.close();
out.write(strTemp);
return null;
}
else if(infoForm.getAction().equals("GetData_C")){
PrintWriter out = servletResponse.getWriter();
String strTemp="<%@ page contentType='text/html;charset=gb2312'%>";
String typing = infoForm.getName();
String CID = infoForm.getMail();
//連數據庫
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").
newInstance();
String url =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=portal";
String user = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select * from P_areacode where id like '" + CID +
"%' and id!=" + CID + "00" + " and jp like '" + typing +
"%' ";
if (typing.equals("") || typing.equals(" ")) {
sql = "select * from P_areacode where id like '" + CID +
"%' and id!=" + CID + "00 ";
}
ResultSet rs = stmt.executeQuery(sql);
String area = "";
String no = "";
while (rs.next()) {
area=rs.getString("area");
no=rs.getString("id");
strTemp+="<div onselect='this.text.value = '"+area+"';$('AID').value = '"+no+"';'><span class='informal'>No."+no+"</span>"+area+"</div>";
}
rs.close();
stmt.close();
conn.close();
out.write(strTemp);
return null;
}
return null;
}
public String toChinese(String ss) {
//處理中文問題,實現編碼轉換
if (ss != null) {
try {
String temp_p = ss;
byte[] temp_t = temp_p.getBytes("ISO8859-1");
ss = new String(temp_t);
} catch (Exception e) {
System.err.println("toChinese exception:" + e.getMessage());
System.err.println("The String is:" + ss);
}
}
return ss;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -