java随笔 2008年

[code="java"]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
偶的JAVA 随记
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<一>表单 提交 条件 JSP-SERVLET-JSP 获取数据库的信息 返回给控制台
1. JSP
用户的半动态表单

<%@ page language="java" pageEncoding="gbk"%>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.jsp.JspWriter"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script lanaguage="javascript">
function btnQuyu_Onclick(q)
{
if(q.selectedIndex==1){
document.frm.city.style.display = "none";
document.frm.county.style.display = "none";
}
if(q.selectedIndex==2){
document.frm.city.style.display = "";
document.frm.county.style.display = "none";
}
if(q.selectedIndex==3){
document.frm.city.style.display = "";
document.frm.county.style.display = "";
}
}
var onecount;
onecount=0;
subcat = new Array();
subcat[0] = new Array("城北供电公司","=025","=1");//county ,分组,countyID
subcat[1] = new Array("城南供电公司","=025","=2");
subcat[2] = new Array("栖霞供电公司","=025","=3");
subcat[3] = new Array("雨花供电公司","=025","=4");
subcat[4] = new Array("溧水供电公司","=025","=6");
subcat[5] = new Array("高淳供电公司","=025","=7");
subcat[6] = new Array("六合供电公司","=025","=8");
subcat[7] = new Array("浦口供电公司","=025","=9");
subcat[8] = new Array("江宁供电公司","=025","=10");
subcat[9] = new Array("计量中心","=025","=12");

subcat[10] = new Array("镇江分县1","0511","004");
subcat[11] = new Array("镇江分县2","0511","005");
subcat[12] = new Array("镇江分县3","0511","006");

onecount=13;

function changelocation(locationid)
{
document.frm.county.length = 0;
var locationid=locationid;
var i;
document.frm.county.options[0] = new Option('====所有区县====','!=0');
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.frm.county.options[document.frm.county.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
</head>
<body>
<form name="frm" action="XxcxServlet" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="12"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="6"></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="4" cellspacing="1">
<tr align="center" bgcolor="#EBEADB">
<td colspan="5" >详细数据查询</td>
</tr>
<tr>
<td height="14" align="left" >选择时间段:</td>
</tr>
<tr>
<td bgcolor="#f4f4f4" colspan="3">
<select name="year1">
<option>2006</option>

</select>日
</td>
</tr>
<tr bgcolor="#FFFFFF">

</tr>
<tr>
<td>
<select name="quyu" οnchange="btnQuyu_Onclick(this);">
<option>==请先选择区域==</option>
<option value="aqs">按全省</option>
<option value="ads">按地市</option>
<option value="aqx">按区县</option>
</select>
</td>
</tr>
<tr bgcolor="#f4f4f4" >

<td>
<!-- 新小知识点 -->
<select name="city" onChange="changelocation(document.frm.city.options[document.frm.city.selectedIndex].value)">
<option value="!=0">==请先选择地市==</option>
<option value="=025">南京</option>
<option value="=0511">镇江</option>
<option value="=0519">常州</option>
<option value="=0516">徐州</option>
<option value="=0512">苏州</option>
<option value="=0510">无锡</option>
<option value="=0513">南通</option>
<option value="=0527">宿迁</option>
<option value="=0514">扬州</option>
<option value="=0523">泰州</option>
<option value="=0517">淮安</option>
<option value="=0515">盐城</option>
<option value="=0518">连云港</option>
</select>
</td>
</tr>

<tr>
<td>
<select name="county">
<option>==所有区县==</option>
</select>
</td>
</tr>
<tr>
<td>
<select name="xxcx">
<option value="!=0">==请选择业务类型==</option>
<option value="!=0">全部</option>
<option value="=1">业务受理</option>
<option value="=2">费用缴纳</option>
<option value="=3">咨询</option>
<option value="=4">查询</option>
<option value="=5">投诉举报</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="确定"></td>
</tr>

</table>
</form>
<script LANGUAGE="javascript">
<!--
changelocation(document.frm.city.options[document.frm.city.selectedIndex].value);
//-->
</script>
</body>
</html>
2.
获取数据库中的信息 返回 JSP

Servlet
package com.suypower.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.suypower.bean.XxcxBean;
import com.suypower.db.DBCon;

public class XxcxServlet extends HttpServlet{
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
//获取表单信息
//1。 获取表单 时间 信息
String year1=request.getParameter("year1");
String month1=request.getParameter("month1");
String day1=request.getParameter("day1");
String year2=request.getParameter("year2");
String month2=request.getParameter("month2");
String day2=request.getParameter("day2");
String time1=year1+"-"+month1+"-"+day1;
String time2=year2+"-"+month2+"-"+day2;
System.out.println("时间范围:"+time1+" and "+time2);
//2。城市ID 转换
String cityID=new String(request.getParameter("city").getBytes("iso8859-1"),"GBK");
System.out.println("城市ID:"+cityID);

//3。指标
String xxcxID=new String(request.getParameter("xxcx").getBytes("iso8859-1"),"GBK");
System.out.println("业务类型:"+xxcxID);

//4.county
String countyID=new String(request.getParameter("county").getBytes("iso8859-1"),"GBK");
//String county=request.getParameter("county");
System.out.println("地市ID:"+countyID);
//这里ywl.jsp页面上已经定义了,不用在这里转换了

//5.区域获取
String quyu=new String(request.getParameter("quyu").getBytes("iso8859-1"),"GBK");
System.out.println("选择区域是按:"+quyu);
Connection con=null;
Statement stmt=null;
HttpSession session =request.getSession();
ArrayList array=new ArrayList();
try{
con=new DBCon().getConnection();
String xxcxSQL="select city_id,operation_id,time_start,time_end,result_id2 from pj_evaluate where time_start between '"+time1+"' and '"+time2+"' and city_id"+cityID+" and county_id"+countyID+" and operation_id"+xxcxID+"";
stmt=con.createStatement();
System.out.println("sql:"+xxcxSQL);
ResultSet xxrs=stmt.executeQuery(xxcxSQL);
while(xxrs.next())
{
XxcxBean xb=new XxcxBean();
String mingcheng=xxrs.getString("city_id");
//在这里转换比较好哦
xb.setMingcheng(mingcheng);
String yewuleixing=xxrs.getString("operation_id");
xb.setYewuleixing(yewuleixing);
String pjkssj=xxrs.getString("time_start");
xb.setPjkssj(pjkssj);
String pjjssj=xxrs.getString("time_end");
xb.setPjjssj(pjjssj);
String pjjg=xxrs.getString("result_id2");
xb.setPjjg(pjjg);

array.add(xb);
}
session.setAttribute("array", array);

}catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(con!=null)
{
con.close();
}
}catch(SQLException ee){ee.toString();}
}
//跳转到结果页面
RequestDispatcher rd=request.getRequestDispatcher("xxcx_jg.jsp");
rd.forward(request, response);
}

}
3。最终结果
<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import ="java.util.ArrayList" %>
<%@ page import ="com.suypower.bean.XxcxBean" %>

<%@ taglib uri="/WEB-INF/extremecomponents" prefix="ec"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<center>
<table border="4">
<tr>
<td>名称</td><td>业务类型</td><td>评价开始时间</td><td>评价结束时间</td><td>评价结果</td>
</tr>
<tr>
<!-- 使用标签 分页显示 session 中的 信息 -->
<%
ArrayList array=new ArrayList();
array=(ArrayList)session.getAttribute("array");
%>
<%
for(int i=0;i<array.size();i++)
{
%>
<%
XxcxBean xb=new XxcxBean();
xb=(XxcxBean)array.get(i);
String mingcheng=xb.getMingcheng();
String ywlx=xb.getYewuleixing();
String startTime=xb.getPjkssj();
String endTime=xb.getPjjssj();
String suc=xb.getPjjg();
%>
<td><%= mingcheng%></td>
<td><%= ywlx%></td>
<td><%= startTime%></td>
<td><%= endTime%></td>
<td><%= suc%></td>
</tr>
<%
}
%>
</table>
</center>
</body>
</html>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<二>一个 下拉 动态 读取 数据库
FOR:
1.
package Test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;

import DBConnect.DBConn;

public class Bumen {
public void getBumen(HttpServletRequest request,JspWriter out) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try {
DBConn db = new DBConn();
conn = db.getConnection();
stmt = conn.createStatement();
String sql = "select distinct bm_name from PJ_BM";
rs = stmt.executeQuery(sql);
String html ="";
while (rs.next())
{
String bm_name=rs.getString("bm_name");
out.print("<option>"+bm_name+"</option>");
}
} catch (Exception e) {
e.getMessage();
} finally {
try {
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.getMessage();
}
}
}
}

2.JSP
<td>
<select name="city">
<option>-请选择城市-</option>
<%
Bumen bm=new Bumen();
bm.getBumen(request,out);
%>
</select>
</td>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<三>.
一个简单的柱状报表
后台 获取 数据库的 SQL 信息 放到 SESSION
前台 显示
<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import="org.jfree.chart.ChartFactory,
java.awt.Color,
java.awt.Font,
org.jfree.chart.JFreeChart,
org.jfree.chart.axis.ValueAxis,
org.jfree.chart.labels.StandardCategoryItemLabelGenerator,
org.jfree.chart.plot.CategoryPlot,
org.jfree.chart.plot.PlotOrientation,
org.jfree.chart.renderer.category.*,
org.jfree.chart.servlet.ServletUtilities,
org.jfree.data.category.CategoryDataset,
org.jfree.data.category.DefaultCategoryDataset" %>
<html>
<body>
<%
String category="江苏营业厅";
double NJhushu=Double.parseDouble(session.getAttribute("NJhushu").toString());
double SZhushu=Double.parseDouble(session.getAttribute("SZhushu").toString());
double WXhushu=Double.parseDouble(session.getAttribute("WXhushu").toString());
double CZhushu=Double.parseDouble(session.getAttribute("CZhushu").toString());
double YZhushu=Double.parseDouble(session.getAttribute("YZhushu").toString());
double NThushu=Double.parseDouble(session.getAttribute("NThushu").toString());
double SQhushu=Double.parseDouble(session.getAttribute("SQhushu").toString());
double XZhushu=Double.parseDouble(session.getAttribute("XZhushu").toString());
double HAhushu=Double.parseDouble(session.getAttribute("HAhushu").toString());
double ZJhushu=Double.parseDouble(session.getAttribute("ZJhushu").toString());
double TZhushu=Double.parseDouble(session.getAttribute("TZhushu").toString());
double YChushu=Double.parseDouble(session.getAttribute("YChushu").toString());
double LYGhushu=Double.parseDouble(session.getAttribute("LYGhushu").toString());
CategoryDataset dataset=this.getDataSet(NJhushu,SZhushu,WXhushu,CZhushu,YZhushu,NThushu,SQhushu,XZhushu,HAhushu,ZJhushu,TZhushu,YChushu,LYGhushu);
String title=category+"受理户数总工号";
JFreeChart chart = ChartFactory.createBarChart3D
(
title,
"城市",
"申请户数",
dataset,
PlotOrientation.VERTICAL,
true,
false,
false
);
String filename = ServletUtilities.saveChartAsPNG(chart,750,350, null, session);

String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
<P ALIGN="CENTER">
<img src="<%= graphURL %>" width=750 height=350 border=0 usemap="#<%= filename %>">
</P>
<%!
public static CategoryDataset getDataSet(double NJhushu,double SZhushu,double WXhushu,double CZhushu,double YZhushu,double NThushu,double SQhushu,double XZhushu,double HAhushu,double ZJhushu,double TZhushu,double YChushu,double LYGhushu)
{
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(NJhushu,"南京","南京");
dataset.addValue(SZhushu, "苏州", "苏州");
dataset.addValue(WXhushu, "无锡", "无锡");
dataset.addValue(CZhushu, "常州", "常州");
dataset.addValue(YZhushu, "扬州", "扬州");
dataset.addValue(NThushu, "南通", "南通");
dataset.addValue(SQhushu, "宿迁", "宿迁");
dataset.addValue(XZhushu, "徐州", "徐州");
dataset.addValue(HAhushu, "淮安", "淮安");
dataset.addValue(ZJhushu, "镇江", "镇江");
dataset.addValue(TZhushu, "泰州", "泰州");
dataset.addValue(YChushu, "盐城", "盐城");
dataset.addValue(LYGhushu, "连云港", "连云港");
return dataset;
}
%>
</body>
</html>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<四>.动态显示数据 导出报表 SQL 读取 到 BEAN 中 这里用的SQL是子查询 全部写入
FOR:
SQL=select a.county_id,a.county_name,
(select count(b.yw_zhh) from pj_yxyw b where b.county_id = a.county_id) as county_zhh,
(select abs(sum(cast(b.yw_rl as int))) from pj_yxyw b where b.county_id = a.county_id)as county_rl,
(select count(c.dfsf_zhh) from pj_yxdfsf c where c.county_id = a.county_id) as county_dfsf_zhh,
(select sum(cast(c.dfsf_je as decimal(35,2))) from pj_yxdfsf c where c.county_id = a.county_id)as county_dfsf_je,
(select count(d.ywsf_zhh) from pj_yxywsf d where d.county_id=a.county_id)as county_ywsf_zhh,
(select sum(cast(e.ywsf_je as decimal(35,2))) from pj_yxywsf e where e.county_id = a.county_id)as county_ywsf_je,
(select count(f.result_id) from pj_evaluate f where f.county_id=a.county_id and result_id='1') as county_my,
(select count(f.result_id) from pj_evaluate f where f.county_id=a.county_id and result_id='3') as county_bmy,
(select count(f.result_id) from pj_evaluate f where f.county_id=a.county_id and result_id='2') as county_yb,
(select count(f.result_id) from pj_evaluate f where f.county_id=a.county_id and result_id='0') as county_wpj
from pj_county a where a.city_id='"+cityID+"'

<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import="org.jfree.chart.ChartFactory,
java.awt.Color,
java.awt.Font,
org.jfree.chart.JFreeChart,
org.jfree.chart.axis.ValueAxis,
org.jfree.chart.labels.StandardCategoryItemLabelGenerator,
org.jfree.chart.plot.CategoryPlot,
org.jfree.chart.plot.PlotOrientation,
org.jfree.chart.renderer.category.*,
org.jfree.chart.servlet.ServletUtilities,
org.jfree.data.category.CategoryDataset,
org.jfree.data.category.DefaultCategoryDataset" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.suypower.bean.YwlBean" %>
<html>

<body>
<%
CategoryDataset dataset;
String category="营业厅";

ArrayList array=new ArrayList();
array=(ArrayList)session.getAttribute("array");
dataset=this.getDataSet(array);

String title=category+"受理总工号统计";
JFreeChart chart = ChartFactory.createBarChart3D(title,
"区县",
"受理总工号统计",
dataset,
PlotOrientation.VERTICAL,
true,
false,
false);

String filename = ServletUtilities.saveChartAsPNG(chart,750, 480, null, session);
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
<P ALIGN="CENTER">
<img src="<%= graphURL %>" border=0 usemap="#<%= filename %>">
</P>

<%!public static CategoryDataset getDataSet(ArrayList array)
{
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int i=0;i<array.size();i++)
{
YwlBean yb=(YwlBean)array.get(i);
System.out.println("城市名字"+yb.getCounty_name()+","+"户数"+yb.getCounty_zhh()+"");
dataset.addValue(Double.parseDouble(yb.getCounty_zhh().toString()),yb.getCounty_name().toString(),yb.getCounty_name().toString());
}
return dataset;
}%>
</body>
</html>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<六>
1.分页组件 extremecomponents 使用 规范 JSP 用到图片 table images 和 JAR ,TLD

<%@ page language="java" pageEncoding="gbk"%>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.jsp.JspWriter"%>
<%@ taglib uri="/WEB-INF/extremecomponents" prefix="ec"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script lanaguage="javascript">
function btnQuyu_Onclick(q)
{
if(q.selectedIndex==1){
document.frm.city.style.display = "none";
document.frm.county.style.display = "none";
}
if(q.selectedIndex==2){
document.frm.city.style.display = "";
document.frm.county.style.display = "none";
}
if(q.selectedIndex==3){
document.frm.city.style.display = "";
document.frm.county.style.display = "";
}
}
var onecount;
onecount=0;
subcat = new Array();
subcat[0] = new Array("城北供电公司","=025","=1");//county ,分组,countyID
subcat[1] = new Array("城南供电公司","=025","=2");
subcat[2] = new Array("栖霞供电公司","=025","=3");
subcat[3] = new Array("雨花供电公司","=025","=4");
subcat[4] = new Array("溧水供电公司","=025","=6");
subcat[5] = new Array("高淳供电公司","=025","=7");
subcat[6] = new Array("六合供电公司","=025","=8");
subcat[7] = new Array("浦口供电公司","=025","=9");
subcat[8] = new Array("江宁供电公司","=025","=10");
subcat[9] = new Array("计量中心","=025","=12");

subcat[10] = new Array("镇江分县1","=0511","004");
subcat[11] = new Array("镇江分县2","=0511","005");
subcat[12] = new Array("镇江分县3","=0511","006");

onecount=13;

function changelocation(locationid)
{
document.frm.county.length = 0;
var locationid=locationid;
var i;
document.frm.county.options[0] = new Option('====所有区县====','!=0');
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.frm.county.options[document.frm.county.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}


function showtable()
{
document.frm.change.value="change";
frm.submit();
}
</script>
</head>
<body>
<form name="frm" action="XxcxServlet" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="12"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="6"></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="4" cellspacing="1">
<tr align="center" bgcolor="#EBEADB">
<td colspan="5" >详细数据查询</td>
</tr>
<tr>
<td height="14" align="left" >选择时间段:</td>
</tr>
<tr>

</select>日
</td>
</tr>
<tr bgcolor="#FFFFFF">

</tr>
<tr>
<td>
<select name="quyu" οnchange="btnQuyu_Onclick(this);">
<option>==请先选择区域==</option>
<option value="aqs">按全省</option>
<option value="ads">按地市</option>
<option value="aqx">按区县</option>
</select>
</td>
</tr>
<tr bgcolor="#f4f4f4" >

<td>
<!-- 新小知识点 -->
<select name="city" onChange="changelocation(document.frm.city.options[document.frm.city.selectedIndex].value)">
<option value="!=0">==请先选择地市==</option>
<option value="=025">南京</option>
<option value="=0511">镇江</option>
<option value="=0519">常州</option>
<option value="=0516">徐州</option>
<option value="=0512">苏州</option>
<option value="=0510">无锡</option>
<option value="=0513">南通</option>
<option value="=0527">宿迁</option>
<option value="=0514">扬州</option>
<option value="=0523">泰州</option>
<option value="=0517">淮安</option>
<option value="=0515">盐城</option>
<option value="=0518">连云港</option>
</select>
</td>
</tr>

<tr>
<td>
<select name="county">
<option>==所有区县==</option>
</select>
</td>
</tr>
<tr>
<td>
<select name="xxcx">
<option value="!=0">==请选择业务类型==</option>
<option value="!=0">全部</option>
<option value="=1">业务受理</option>
<option value="=2">费用缴纳</option>
<option value="=3">咨询</option>
<option value="=4">查询</option>
<option value="=5">投诉举报</option>
</select>
</td>
</tr>
<tr>
<td><input type="button" value="确定" οnclick="showtable()">
<input type="hidden" name="change">
</td>
</tr>

</table>
<div align="center" id="cz" >
<ec:table
action="${pageContext.request.contextPath}/XxcxServlet"
items="array"
var="a"
imagePath="${pageContext.request.contextPath}/images/table/*.gif"
width="99%"
tableId="resultTable1"
rowsDisplayed="10"
form="frm"
filterable="false"
sortable="false"
autoIncludeParameters="false">
<ec:row>
<ec:column property="mingcheng" title="【名称】" width="10%"></ec:column>
<ec:column property="yewuleixing" title="【业务类型】" width="15%"></ec:column>
<ec:column property="pjkssj" title="【评价开始时间】" width="25%"></ec:column>
<ec:column property="pjjssj" title="【评价结束时间】" width="25%"></ec:column>
<ec:column property="pjjg" title="【评价结果】" width="20%"></ec:column>
</ec:row>
</ec:table>
</div>
</form>
<script LANGUAGE="javascript">
<!--
changelocation(document.frm.city.options[document.frm.city.selectedIndex].value);
//-->
</script>
</body>
</html>
2.
SERVLET

package com.suypower.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.suypower.bean.XxcxBean;
import com.suypower.db.DBCon;

public class XxcxServlet extends HttpServlet{
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
//获取表单信息
//1。 获取表单 时间 信息
String year1=request.getParameter("year1");
String month1=request.getParameter("month1");
String day1=request.getParameter("day1");
String year2=request.getParameter("year2");
String month2=request.getParameter("month2");
String day2=request.getParameter("day2");
String time1=year1+"-"+month1+"-"+day1;
String time2=year2+"-"+month2+"-"+day2;
System.out.println("时间范围:"+time1+" and "+time2);
//2。城市ID 转换
String cityID=new String(request.getParameter("city").getBytes("iso8859-1"),"GBK");
System.out.println("城市ID:"+cityID);

//3。指标
String xxcxID=new String(request.getParameter("xxcx").getBytes("iso8859-1"),"GBK");
System.out.println("业务类型:"+xxcxID);

//4.county
String countyID=new String(request.getParameter("county").getBytes("iso8859-1"),"GBK");
//String county=request.getParameter("county");
System.out.println("地市ID:"+countyID);
//这里ywl.jsp页面上已经定义了,不用在这里转换了

//5.区域获取

//--------------------------------------------------------------------------------//

String change=request.getParameter("change");

//--------------------------------------------------------------------------------//
String quyu=new String(request.getParameter("quyu").getBytes("iso8859-1"),"GBK");
System.out.println("选择区域是按:"+quyu);
Connection con=null;
Statement stmt=null;
HttpSession session =request.getSession();
ArrayList array=new ArrayList();

if(change.equals("change"))
{
try{
con=new DBCon().getConnection();
String xxcxSQL="select city_id,operation_id,time_start,time_end,result_id2 from pj_evaluate where time_start between '"+time1+"' and '"+time2+"' and city_id"+cityID+" and county_id"+countyID+" and operation_id"+xxcxID+"";
stmt=con.createStatement();
System.out.println("sql:"+xxcxSQL);
ResultSet xxrs=stmt.executeQuery(xxcxSQL);
while(xxrs.next())
{
XxcxBean xb=new XxcxBean();
String mingcheng=xxrs.getString("city_id");
//在这里转换比较好哦
if("025".equals(mingcheng))mingcheng="南京";
if("0512".equals(mingcheng))mingcheng="苏州";
xb.setMingcheng(mingcheng);

String yewuleixing=xxrs.getString("operation_id");
if("1".equals(yewuleixing))yewuleixing="业务受理";
if("2".equals(yewuleixing))yewuleixing="费用缴纳";
if("3".equals(yewuleixing))yewuleixing="咨询";
if("4".equals(yewuleixing))yewuleixing="查询";
if("5".equals(yewuleixing))yewuleixing="投诉举报";
xb.setYewuleixing(yewuleixing);

String pjkssj=xxrs.getString("time_start");
xb.setPjkssj(pjkssj);
String pjjssj=xxrs.getString("time_end");
xb.setPjjssj(pjjssj);
String pjjg=xxrs.getString("result_id2");
if("1".equals(pjjg))pjjg="满意";
if("3".equals(pjjg))pjjg="不满意";
if("2".equals(pjjg))pjjg="一般";
if("0".equals(pjjg))pjjg="未评价";
xb.setPjjg(pjjg);

array.add(xb);
}
session.setAttribute("array", array);

}catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(con!=null)
{
con.close();
}
}catch(SQLException ee){ee.toString();}
}
}
//跳转到结果页面
RequestDispatcher rd=request.getRequestDispatcher("xxcx.jsp");
rd.forward(request, response);
}

}

3.WEB.XML
<taglib>
<taglib-uri>/WEB-INF/extremecomponents</taglib-uri>
<taglib-location>/WEB-INF/extremecomponents.tld</taglib-location>
</taglib>
</jsp-config>

4。原始未分页 显示

<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import ="java.util.ArrayList" %>
<%@ page import ="com.suypower.bean.XxcxBean" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<center>
<table border="4">
<tr>
<td>名称</td><td>业务类型</td><td>评价开始时间</td><td>评价结束时间</td><td>评价结果</td>
</tr>
<tr>
<!-- 使用标签 分页显示 session 中的 信息 -->
<%
ArrayList array=new ArrayList();
array=(ArrayList)session.getAttribute("array");
%>
<%
for(int i=0;i<array.size();i++)
{
%>
<%
XxcxBean xb=new XxcxBean();
xb=(XxcxBean)array.get(i);
String mingcheng=xb.getMingcheng();
String ywlx=xb.getYewuleixing();
String startTime=xb.getPjkssj();
String endTime=xb.getPjjssj();
String suc=xb.getPjjg();
%>
<td><%= mingcheng%></td>
<td><%= ywlx%></td>
<td><%= startTime%></td>
<td><%= endTime%></td>
<td><%= suc%></td>
</tr>
<%
}
%>
</table>
</center>
</body>
</html>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<七>
框架frameset模块 简单 代码 frameset head left right foot
1. frameset .jsp
<%@ page language="java" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>营业厅窗口服务评价系统</title>
</head>
<frameset frameborder="0" frameSpacing="0" rows="90,480,45">
<frame name="head" src="head.jsp" noResize scrolling="no" marginwidth="0" marginheight="0">

<frameset border="false" frameSpacing="0" frameBorder="0" cols="170,560">
<frame name="left" marginWidth="0" marginHeight="0" src="left.jsp" noResize scrolling="no">
<frame name="right" marginWidth="0" src="right.jsp" scrolling="auto" noResize>
</frameset>

<frame name="bottom" src="foot.jsp" noresize scrolling="no" marginwidth="0" marginheight="0">
</frameset>
</html>

2.head .jsp
<%@ page language="java" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/title01.gif" width="1009" height="100"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="8"></td>
</tr>
</table>
</body>
</html>
3.left.jsp
<%@ page language="java" pageEncoding="gb2312"%>
<html>
<body>
<head>
<meta http-equiv="refresh" content="15">
</head>
<table width="1024" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="238" height="496" valign="top" background="images/left01.gif">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="80" align="center" valign="bottom" class="a1">${qs_hs}</td>
</tr>
<tr>
<td height="80" align="center" valign="bottom"><span class="a1">${dfsf_je }</span></td>
</tr>
<tr>
<td height="75" align="center" valign="bottom"><span class="a1">${dfsf_zhh }</span></td>
</tr>
<tr>
<td height="75" align="center" valign="bottom"><span class="a1">${ywsf_zhh }</span></td>
</tr>
<tr>
<td height="70" align="center" valign="bottom"><span class="a1">${qs_rl }</span></td>
</tr>
<tr>
<td height="75" align="center" valign="bottom"><span class="a1">${ywsf_je }</span></td>
</tr>
</table></td>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="9" background="images/bg01.gif"></td>
</tr>
</table>

4.right .jsp

<%@ page language="java" pageEncoding="gb2312"%>
<html>
<head>
<title>内容页面</title>
<link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body style='OVERFLOW:SCROLL;OVERFLOW-X:HIDDEN;'>
<form name="form1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="363"></td><!-- <img src="images/login01.gif" width="777" height="480"> -->
</tr>
</table>
</form>
</body>
</html>

5.foot .jsp

<%@ page language="java" pageEncoding="gb2312"%>
<html>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/di01.gif" width="1024" height="40" border="0" usemap="#Map"></td>
</tr>
</table>
<map name="Map">
<area shape="rect" coords="26,11,144,31" href="ShowCharServlet?param=ywl" target="right">
<area shape="rect" coords="277,12,381,28" href="ShowCharServlet?param=dfzj" target="right">
<area shape="rect" coords="168,11,255,30" href="ShowCharServlet?param=myd" target="right">
<area shape="rect" coords="409,11,520,32" href="ShowCharServlet?param=dfywl" target="right">
<area shape="rect" coords="552,11,648,32" href="ShowCharServlet?param=ywzj" target="right">
<area shape="rect" coords="678,10,802,31" href="ShowCharServlet?param=ywslhs" target="right">
<area shape="rect" coords="834,11,974,31" href="ShowCharServlet?param=ywslrl" target="right">
</map>
</body>
</html>

FOR:其他参考代码
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
left .jsp

<%@ page language="java" pageEncoding="gbk"%>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td background="images/bg01c.gif" width="20">
</td>
<td valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td background="images/bg01d.gif" bgcolor="#f5fffa" height="34" style="width: 708px">
 </td>
</tr>
<tr>
<td bgcolor="#f5fffa" valign="top" style="width: 708px">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="height: 19px">
 </td>
</tr>
</table>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20">
<font color="#000000">
<img height="20" src="images/USER0.GIF" width="20" />
</font>
</td>
<td>
<font color="#000000"> 用户名:</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<img align="absMiddle" border="0" height="22" src="images/midminus1.gif" width="16" /><img
align="absMiddle" border="0" height="16" src="images/FOLDER01.GIF" width="16" />
<a href="###实现此功能###"><span style="color: #333333">评价数据统计</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" height="22" src="images/LINE.GIF" width="16" /><img align="absMiddle"
src="images/MIDBLK.GIF" /><img align="absMiddle" border="0" height="16" src="images/MAILBOX.GIF"
width="16" />
<a href="yeWu.do?param=yewufenbu" target="right"><span style="color: #333333">业务分布统计</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" src="images/LINE.GIF" /><img align="absMiddle" src="images/MIDBLK.GIF" /><img
align="absMiddle" border="0" height="16" src="images/SEND_BOX.GIF" width="16" />
<a href="MainServlet?param=manyishuju" target="right"><span style="color: #333333">满意数据分析</span></a></td>
</tr>

<tr style="color: #333333">
<td style="height: 22px">
<img align="absMiddle" src="images/LINE.GIF" /><img align="absMiddle" src="images/MIDBLK.GIF" /><img
align="absMiddle" border="0" height="16" src="images/SEARCH.GIF" width="16" />
<a href="MainServlet?param=xiangxishuju" target="right"><span style="color: #333333">详细数据查询</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" border="0" height="22" src="images/midminus1.gif" width="16" /><img
align="absMiddle" border="0" height="16" src="images/FOLDER01.GIF" width="16" />
<a href="##############"><span style="color: #333333">营销数据统计</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" src="images/LINE.GIF" /><img align="absMiddle" src="images/MIDBLK.GIF" /><img
align="absMiddle" border="0" height="16" src="images/TOOLS.GIF" width="16" />
<a href="MainServlet?param=yewuliang" target="right"><span style="color: #333333">业务量统计</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" src="images/LINE.GIF" /><img align="absMiddle" src="images/MIDBLK.GIF" /><img
align="absMiddle" border="0" height="16" src="images/TEMP_BOX.GIF" width="16" />
<a href="MainServlet?param=zijin" target="right""><span style="color: #333333">业务资金统计</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" height="22" src="images/LINE.GIF" width="16" /><img align="absMiddle"
src="images/MIDBLK.GIF" /><img align="absMiddle" border="0" height="16" src="images/SIZE.GIF"
width="16" />
<a href="MainServlet?param=dfsf" target="right""><span style="color: #333333">电费收费统计</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" border="0" height="22" src="images/midminus1.gif" width="16" /><img
align="absMiddle" border="0" height="16" src="images/FOLDER01.GIF" width="16" />
<a href="###########3#"><span style="color: #333333">组织机构管理</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" height="22" src="images/LINE.GIF" width="16" /><img align="absMiddle"
src="images/MIDBLK.GIF" /><img align="absMiddle" border="0" height="16" src="images/REFUSE.GIF"
width="16" />
<a href="yeWu.do?param=dishi" target="right""><span style="color: #333333">地市信息</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" height="22" src="images/LINE.GIF" width="16" /><img align="absMiddle"
src="images/MIDBLK.GIF" /><img align="absMiddle" border="0" height="16" src="images/NEW_MAIL.gif"
width="16" />
<a href="yeWu.do?param=guiyuan" target="right""><span style="color: #333333">柜员信息</span></a></td>
</tr>

<tr style="color: #333333">
<td style="height: 22px">
<img align="absMiddle" border="0" height="22" src="images/midminus1.gif" width="16" /><img
align="absMiddle" border="0" height="16" src="images/FOLDER01.GIF" width="16" />
<a href="#########3#"><span style="color: #333333">系统管理</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" height="22" src="images/LINE.GIF" width="16" /><img align="absMiddle"
src="images/MIDBLK.GIF" /><img align="absMiddle" border="0" height="16" src="images/take_mail.gif"
width="16" />
<a href="yeWu.do?param=yonghu" target="right""><span style="color: #333333">用户管理</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" height="22" src="images/LINE.GIF" width="16" /><img align="absMiddle"
src="images/MIDBLK.GIF" /><img align="absMiddle" border="0" height="16" src="images/RESUME.GIF"
width="16" />
<a href="infor.do" target="right"><span style="color: #333333">个人信息</span></a></td>
</tr>

<tr style="color: #333333">
<td>
<img align="absMiddle" border="0" height="22" src="images/LASTBLK.GIF" width="16" /><img
align="absMiddle" border="0" height="16" src="images/EXIT.GIF" width="16" />
<a href="login.jsp" target="right"><span
style="color: #333333"> 退  出</span></a></td>
</tr>

</table>
<p>
<br />
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<八>一个简单的 不安全的 login .jsp

package com.suypower.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.suypower.db.DBCon;

public class LoginServlet extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
String userid=request.getParameter("userId");
String psw=request.getParameter("userMm");
HttpSession session=request.getSession();
session.setAttribute("userid",userid);
try{
Connection con=new DBCon().getConnection();
Statement stmt=con.createStatement();
String sql1="select count(User_ID) as zongshu from PJ_User where User_ID='"+userid+"' and User_MM='"+psw+"'";
ResultSet rs1=stmt.executeQuery(sql1);
rs1.next();
String noing=rs1.getString("zongshu");
if(noing.equals("0"))
{
RequestDispatcher rd=request.getRequestDispatcher("error.jsp");
rd.forward(request, response);
}else
{
RequestDispatcher rd=request.getRequestDispatcher("frameset.jsp");
rd.forward(request, response);
}

}catch(SQLException e)
{
e.printStackTrace();
}
}

}
FOR; 用struts + hibernate 验证用户 login .jsp
package com.suypower.struts;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import DBConnect.DBConn;

public class LoginAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)throws Exception
{
// System.out.print("11111111111111111111");
ActionForward actionForward=new ActionForward();
// LoginForm lf=(LoginForm)form;
// String userID=lf.getUserId();
// String userMM=lf.getUserMm();
// System.out.println("222222222222222222");
// String sql="from PjUser as pj where pj.userId=:PJuserId and pj.userMm=:PJuserMm";
// //判断用户
// System.out.print("3333333333333");
// try{
// Session session=HibernateSessionFactory.getSession();
// //HibernateSessionFactory.getSession();
// //new Configuration().configure().buildSessionFactory().openSession();
// System.out.println("44444444444444");
// Transaction tx=session.beginTransaction();
// System.out.println("5555555555555555");
// Query query=session.createQuery(sql);
// System.out.println("666666666666666666");
// query.setString("PJuserId", userID);
// query.setString("PJuserMm", userMM);
// tx.commit();
// System.out.println("777777777777777777777");
// if(query.list().size()>0)
// {
// session.close();
// return mapping.findForward("frameset");
// }
// else
// {
// return mapping.findForward("error");
// }
// }catch(HibernateException e)
// {
// e.printStackTrace();
// }
// return actionForward;
String userid=request.getParameter("userId");
String psw=request.getParameter("userMm");
HttpSession session=request.getSession();
session.setAttribute("userid",userid);

Connection con=new DBConn().getConnection();
// String sql="select User_ID,User_MM,Popedom_ID from PJ_User where User_ID='"+userid+"' and User_MM='"+psw+"'";
// System.out.print(sql);
Statement stmt=con.createStatement();
// ResultSet rs=stmt.executeQuery(sql);
// while(rs.next())
// {
// String name=rs.getString("User_ID");
// String password=rs.getString("User_MM");
// String popodomID=rs.getString("Popedom_ID");
// session.setAttribute("popodomID", popodomID);
// }
String sql1="select count(User_ID) as zongshu from PJ_User where User_ID='"+userid+"' and User_MM='"+psw+"'";
ResultSet rs1=stmt.executeQuery(sql1);
rs1.next();
String noing=rs1.getString("zongshu");
System.out.println("ddddddddddddddd"+noing);
if(noing.equals("0"))
{
System.out.println("wwwwwwwwwwwww"+rs1.getRow());
return actionForward=mapping.findForward("error");
}
if(rs1.getRow()>0)
{
System.out.println("sssssssssssssss"+rs1.getRow());
return actionForward=mapping.findForward("frameset");
}
return actionForward;
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<九>: 一个地市 信息 显示 绑订到数据库 显示 连接 (联到删除 什么对应的 功能)
<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import="Test.SjbdDishi" %>
<html>
<body>
<div align="center">
<table>
<tr><th>统计信息:共有${count }个地市<th></tr>
</table>
<br>
<table width="75%" border=1>
<tr><th>地市</th><th>地市区号</th><th>查看</th></tr>
<%
SjbdDishi ds=new SjbdDishi();
ds.getDSsjbd(request,out);
%>
</table>
</div>
</body>
</html>

package Test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;

import DBConnect.DBConn;

public class SjbdDishi {
public void getDSsjbd(HttpServletRequest request,JspWriter out)
{
HttpSession session=request.getSession();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try {
DBConn db = new DBConn();
conn = db.getConnection();
stmt = conn.createStatement();
String sql = "select City_ID,City_NAME from dbo.PJ_City";
rs = stmt.executeQuery(sql);
while (rs.next())
{
int count=rs.getRow();
session.setAttribute("count", count);
String cityID=rs.getString("City_ID");
String cityNAME=rs.getString("City_NAME");
out.print("<tr><td>"+cityID+"</td><td>"+cityNAME+"</td>");
out.print("<td><a href=dsView.do?param="+rs.getString("City_ID")+">查看</a></td>");
}
} catch (Exception e) {
e.getMessage();
} finally {
try {
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
}
}
}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
jdbc 连接
package com.suypower.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBCon {
final private String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
final private String driverURL="jdbc:sqlserver://172.23.23.3:1433;databaseName=pjtest";
final private String username="pj";
final private String password="pj3023";

Connection con=null;
Statement stmt=null;
ResultSet rs=null;
public Connection getConnection()
{
try
{
Class.forName(driverName);
}catch(ClassNotFoundException e)
{
System.out.println("%%%连接驱动失败%%%");
e.printStackTrace();
}
try
{
con=DriverManager.getConnection(driverURL,username,password);
}catch(SQLException e)
{
e.printStackTrace();
System.out.println("%%%连接数据库失败%%%");
}
finally
{
}
return con;
}
}
%%%%%%%%%%%%%%%%%%%%%%-2007-12-18-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
extremeComponents 的删除 和编辑弹出页面 实现

1。分页信息输出
<div align="center" id="cz" >
<ec:table
action="${pageContext.request.contextPath}/BmServlet"
items="arrayBM"
var="a"
imagePath="${pageContext.request.contextPath}/images/table/*.gif"
width="99%"
tableId="resultTable1"
rowsDisplayed="10"
form="frm"
filterable="false"
sortable="false"
autoIncludeParameters="false">
<ec:row>
<ec:column property="city_id" title="【所属地市】" width="16%"></ec:column>
<ec:column property="county_id" title="【分县公司】" width="16%"></ec:column>
<ec:column property="bm_id" title="【所属部门】" width="16%"></ec:column>
<ec:column property="person_id" title="【员工工号】" width="16%"></ec:column>
<ec:column property="person_name" title="【员工姓名】" width="16%"></ec:column>

<ec:column property="【编辑】" title="" width="10%">
<input type="button" value="编辑" name="space">
</ec:column>

<ec:column property="【删除】" title="" width="10%">
<input type="button" value="删除" οnclick="del('${a.person_id }')">
</ec:column>

</ec:row>
</ec:table>
<input type="hidden" name="shanchu">
</div>
2。
。。。。
。。。
function del(person_id)
{
document.frm.change.value="shanchu";
document.frm.shanchu.value=person_id;
frm.submit();
}
</script>

3。servlet 获取参数 然后 连接数据库 执行删除
。。。
。。。。
if(param.equals("shanchu"))
{
String person_id=request.getParameter("shanchu");
//写SQL语句 删除
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
System.out.println(person_id);
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
编辑
思路:用分页组件 extremecomponents 实现 编辑
然后 传参数
用JS实现 弹出页面
页面上是用JSP
然后用的是 JS限制格式
JSP action=到 SERVLET
SERVLET 获取 参数
连接数据库 update 数据 即可
很清晰的思路哦
代码:
<div align="center" id="cz" >
<ec:table
action="${pageContext.request.contextPath}/BmServlet"
items="arrayBM"
var="a"
imagePath="${pageContext.request.contextPath}/images/table/*.gif"
width="99%"
tableId="resultTable1"
rowsDisplayed="10"
form="frm"
filterable="false"
sortable="false"
autoIncludeParameters="false">
<ec:row>
<ec:column property="city_id" title="【所属地市】" width="16%"></ec:column>
<ec:column property="county_id" title="【分县公司】" width="16%"></ec:column>
<ec:column property="bm_id" title="【所属部门】" width="16%"></ec:column>
<ec:column property="person_id" title="【员工工号】" width="16%"></ec:column>
<ec:column property="person_name" title="【员工姓名】" width="16%"></ec:column>

<ec:column property="【编辑】" title="" width="10%">
<input type="button" value="编辑" οnclick="edit('${a.person_id }','${a.city_id }','${a.county_id }','${a.bm_id }','${a.person_name }')" >
</ec:column>

<ec:column property="【删除】" title="" width="10%">
<input type="button" value="删除" οnclick="del('${a.person_id }')">
</ec:column>

</ec:row>
</ec:table>
<input type="hidden" name="shanchu">
</div>

....
...
function edit(person_id,city_id,county_id,bm_id,person_name)
{
url="edit.jsp?personid="+person_id+"&cityid="+city_id+"&countyid="+county_id+"&bmid="+bm_id+"&personName="+person_name;
//alert(url);
window.open(url,'newwindow','height=250,width=400,top=200,left=200,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
}

</script>

JSP
<%@ page language="java" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<%
String personid=new String(request.getParameter("personid").getBytes("iso8859-1"),"gbk");
String cityid=new String(request.getParameter("cityid").getBytes("iso8859-1"),"gbk");
String countyid=new String(request.getParameter("countyid").getBytes("iso8859-1"),"gbk");
String bmid=new String(request.getParameter("bmid").getBytes("iso8859-1"),"gbk");
String personName=new String(request.getParameter("personName").getBytes("iso8859-1"),"gbk");
%>
<form action="EditServlet" method="post">
<table>
<tr><td>用户ID:</td><td><%= personid %></td></tr>
<tr><td>用户名:</td><td><%= personName %></td></tr>
<tr><td>城市:</td><td><%= cityid %></td></tr>
<tr><td>区县:</td><td><input type="text" value="<%= countyid %>" name="aaa"></td></tr>
<tr><td>部门:</td><td><input type="text" value="<%= bmid %>" name="bbb"></td></tr>
<tr>
<td>是否为服务人员:</td>
<td>
<select name="fuwu">
<option>是</option>
<option>否</option>
</select>
</td></tr>
<tr><td><input type="submit" value="确定"></td></tr>
</table>
</form>
</body>
</html>

Servlet

。。。。。。。。。
获取表单信息 写SQL 更新 即可 很简单的 这里就不给代码了

//2007-12-19//。。。。。。。。。。。。。。。AJAX 联动。。。。。。。。。。。。。。。
ajax
<%@ page language="java" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
This is my ajax JSP page. <br>
<head>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActionXObject)
{
xmlHttp=new ActionXObject("Microsoft.XMLHTTP");
}
elst if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
function startRequest()
{
createXMLHttpRequest();
xmlHttp.onreadystatechange=handleStateChange;
xmlRequest.open("get","innerHTML",true);
xmlHttp.send(null);
}
function handleStateChange()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
document.getElementById("results").innerHTML=xmlHttp.responseText;
}
}
}
}
</script>
</head>
<body>
<form action="#">
<input type="button" value="ajax" οnclick="startRequest();"/>
<div id="results"></div>
</form>
</body>
</html>
innerHTML.xml
...
.....
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ajax 实现级联下拉 更新 数据库
<head>
<script language ="javascript">

var http_request = false;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{ //IE浏览器
http_request=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}

function Change_Select(){
var cityID=document.frm.city.value;
createXMLHttpRequest();
http_request.onreadystatechange=callback;
http_request.open("get","TestServlet?cityid="+cityID,true);
http_request.send(null);
}
function callback(){
if(http_request.readyState == 4)
{
if(http_request.status == 200)
{
var str=http_request.responseText;
if(str!=null)
{
var field=str.split("|");
}
document.getElementById("county").length=0;//调用之前先置为空
for(var i=0;i<field.length-1;i++)
{
var option=field[i].split(",");
document.frm.county.add(new Option(option[0],option[0]));

}
}else {
alert("http_request.status == 200 失败");
}
}

}
</script>


</head>
<body>
<form name="frm" action="YwlServlet" method="post">
.......................

<select name="city" onChange="Change_Select()">
<option>==请先选择地市==</option>
<option value="025">南京</option>
<option value="0511">镇江</option>
<option value="0519">常州</option>
....................

.................
...
<td>
<select name="county">
<option>==所有区县==</option>
</select>
</td>
..............

servlet
...
..
package com.suypower.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.suypower.db.DBCon;

public class TestServlet extends HttpServlet{

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
response.setContentType("text/html");
response.setCharacterEncoding("gb2312");
doPost(request,response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
//String cityID=request.getParameter("cityid");

Connection con=null;
Statement stmt=null;
PrintWriter out=response.getWriter();
request.setCharacterEncoding("gb2312");
response.setContentType("text/html");
response.setCharacterEncoding("gb2312");
try{
con=new com.suypower.db.DBCon().getConnection();
stmt=con.createStatement();
String sql="select county_name from pj_county";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
String county_name=rs.getString("county_name");
out.print(county_name+"|");
}
}catch(SQLException e){e.printStackTrace();}
}


}
¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥
程雨__级联菜单__树型结构
不要着急 我们 来 先看看API

Overview
Functions
add
openAll
closeAll
openTo
Configuration
Functions
add()
Adds a node to the tree.
Can only be called before the tree is drawn.

id, pid and name are required.

Parameters
Name Type Description
id Number Unique identity number.
pid Number Number refering to the parent node. The value for the root node has to be -1.
name String Text label for the node.
url String
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值