1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| package tw.com.vibo.www.tag;
import java.io.IOException;
import java.sql.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
import tw.com.vibo.www.singleton.connectionDB;
public class modifySrc extends BodyTagSupport {
protected int pageRow;
HttpServletRequest request;
public modifySrc(){
super();
}
public void setPageContext(PageContext pageContext)
{
this.pageContext = pageContext;
request =(HttpServletRequest) pageContext.getRequest();
}
public int doAfterBody(){
Hashtable rsHashtable;
int countRec=0;
try{
Vector vector = this.getResult();
JspWriter out = this.getPreviousOut();
Iterator iterator = vector.iterator();
if (vector.isEmpty()) out.print("<tr >\r\nNo Data Found !!\r\n</tr>");
System.out.print(" test prepare to run while(iterator.hasNext( ))... ");
while (iterator.hasNext()){
rsHashtable = (Hashtable) iterator.next();
System.out.print(" test rsHashtable create... ");
countRec++;
if(countRec%2 == 0) out.print("<tr>\r\n");
else out.print("<tr bgcolor=\"#D1DAE9\">\r\n");
out.print("<td width=\"73\" height=\"20\"><div align=\"center\">"+countRec+"</div></td>\r\n");
out.print("<td width=\"111\" height=\"20\"><div align=\"center\">"+rsHashtable.get("channel_type")+"</div></td>\r\n");
out.print("<td width=\"128\" height=\"20\"><div align=\"center\">"+rsHashtable.get("src_id")+"</div></td>\r\n");
out.print("<td width=\"92\" height=\"20\"><div align=\"center\">"+rsHashtable.get("src_desc")+"</div></td>\r\n");
out.print("<td width=\"109\" height=\"20\"><div align=\"center\">"+rsHashtable.get("channel_desc")+"</div></td>\r\n");
out.print("<td width=\"109\" height=\"20\"><div align=\"center\">"+rsHashtable.get("eng_name")+"</div></td>\r\n");
out.print("<td width=\"93\" height=\"20\" valign=\"middle\"><div align=\"center\"><form name=\"form"+countRec+"\" method=\"post\" id=\"form"+countRec+"\" action=\"modifySrcResult.jsp\"> " +
" <input name=\"channel_type\" type=\"hidden\" id=\"channel_type["+countRec+"]\" value=\""+rsHashtable.get("channel_type")+"\"> " +
" <input name=\"src_id\" type=\"hidden\" id=\"src_id["+countRec+"]\" value=\""+rsHashtable.get("src_id")+"\"> " +
" <input name=\"src_desc\" type=\"hidden\" id=\"src_desc["+countRec+"]\" value=\""+rsHashtable.get("src_desc")+"\"> " +
" <input name=\"channel_desc\" type=\"hidden\" id=\"channel_desc["+countRec+"]\" value=\""+rsHashtable.get("channel_desc")+"\"> " +
" <input name=\"eng_name\" type=\"hidden\" id=\"eng_name["+countRec+"]\" value=\""+rsHashtable.get("eng_name")+"\"> " +
" <input name=\"submit1\" type=\"submit\" id=\"submit["+countRec+"]\" value=\" 修改 \" onClick=\"check('"+countRec+"');\" > "+
" </form></div></td> " );
out.print("</tr>\r\n");
}
System.out.print(" test while( ) loop exit, countRec: "+countRec+" ");
}catch (SQLException e) {
System.out.print(" test SQL exception in doAfterBody();... ");
e.printStackTrace();
}catch (IOException e) {
System.out.print(" test IO exception in doAfterBody();... ");
e.printStackTrace();
}
return SKIP_BODY;
}
protected Vector getResult() throws SQLException
{
Vector ini_vector = new Vector();
Connection conn;
PreparedStatement ps = null;
ResultSet rs;
conn = connectionDB.getInstance().getConnection();
try {
String queryString;
queryString = " select st.channel_type,st.src_id,st.src_desc,st.channel_desc,st.eng_name "+
" from src_tab st " +
" where 1=1 " +
((request.getParameter("Channel").length()!=0) ? " and st.channel_type = "+request.getParameter("Channel") : "" ) +
"order by st.src_id ";
ps = conn.prepareStatement(queryString);
rs = ps.executeQuery();
if (rs != null)
{
while (rs.next())
{
Hashtable ht = new Hashtable();
ht.put("channel_type", rs.getObject("channel_type"));
ht.put("src_id", rs.getObject("src_id"));
ht.put("src_desc", rs.getObject("src_desc"));
ht.put("channel_desc", rs.getObject("channel_desc"));
ht.put("eng_name", rs.getObject("eng_name"));
ini_vector.add(ht);
}
}
if (ps != null) ps.close();
}
catch (SQLException e) {
System.out.print(" test SQL exception in getResult( ); ");
e.printStackTrace();
}
finally{
try{
if (ps != null) ps.close();
if (conn != null) conn.close();
}
catch (Exception ex) {
System.out.print(" test exception in getResult( ) \"finally\"... ");
ex.printStackTrace();
}
}
return ini_vector;
}
public int getPageRow() {
return pageRow;
}
public void setPageRow(int i) {
pageRow = i;
}
}
|