servlet应用具体实例
web,xml应用文件
1.<filter>参数
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--多数据源支持监听 -->
java服务端: 每一个file对应一个具体的类,他会在web应用的servlet应用之响应
/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package org.springframework.web.filter; import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class CharacterEncodingFilter extends OncePerRequestFilter {
private String encoding;
private boolean forceEncoding = false; public void setEncoding(String encoding) {
this.encoding = encoding;
} public void setForceEncoding(boolean forceEncoding) {
this.forceEncoding = forceEncoding;
} protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
if ((this.encoding != null)
&& (((this.forceEncoding) || (request.getCharacterEncoding() == null)))) {
request.setCharacterEncoding(this.encoding);
if (this.forceEncoding) {
response.setCharacterEncoding(this.encoding);
}
}
filterChain.doFilter(request, response);
}
}
案例二xml
<!--多数据源支持监听 -->
<filter>
<filter-name>dataSourceFilter</filter-name>
<filter-class>cn.jasgroup.jasframework.dataaccess.filter.DataSourceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>dataSourceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
java服务器端
/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package cn.jasgroup.jasframework.dataaccess.filter; import cn.jasgroup.jasframework.dataaccess.observer.DataSourceObserver;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; public class DataSourceFilter implements Filter {
public void destroy() {
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
String datasource = req.getParameter("dataSourceName");
if ((datasource != null) && (!("".equals(datasource)))) {
DataSourceObserver.setDataSourceName(datasource);
}
filterChain.doFilter(request, response);
} public void init(FilterConfig arg0) throws ServletException {
}
}
respoonser实例
/**
* 查询任意圈定区域所在工区信息
*
* @param request
* @param response
* @return
* @throws IOException
*/
@RequestMapping("/queryWorkareaInfo")
@ResponseBody
public void queryWorkareaInfo(HttpServletRequest request, HttpServletResponse response) throws IOException {
WorkareaInfoBo winfoBo = new WorkareaInfoBo();
String workareaName = request.getParameter("workareaName"); String wellIds = request.getParameter("wellIds");
String wellNames = request.getParameter("wellNames");
try {
wellNames = URLDecoder.decode(wellNames, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // 生产层位
String cengwei = request.getParameter("cengwei"); String date_start = request.getParameter("date_start");
String date_end = request.getParameter("date_end");
if (StringUtils.isNotBlank(cengwei)) {
try {
cengwei = URLDecoder.decode(cengwei, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!cengwei.equals("所有层位")) {
String cengwei_wellname = "";
String[] wellarr = wellNames.split(";");
wellNames="";
for (String val : wellarr) {
cengwei_wellname += "'" + val + "',";
}
cengwei_wellname += "@";
cengwei_wellname = cengwei_wellname.replace(",@", ""); // cengwei = getChildren(cengwei); // wellNames = "";
// String hql_per = "from Perforationdata where perforationposition in('" + cengwei + "') and wellnum in("
// + cengwei_wellname + ")";
String hql_per = "select distinct(jh) from YCSY_NEWHORIZON where cw in('" + cengwei + "') and jh in("
+ cengwei_wellname + ")"; List<NewHorizon> list = workareaInfoService.queryPerforation(hql_per);
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
NewHorizon perforationdata = (NewHorizon) iterator.next();
wellNames += perforationdata.getJh() + ";";
}
}
}
// 生产层位end
/*
* try { wellNames = new
* String(wellNames.getBytes("ISO-8859-1"),"UTF-8"); } catch
* (UnsupportedEncodingException e1) { // TODO Auto-generated catch
* block e1.printStackTrace(); }
*/ Map<String, Object> map = new HashMap<String, Object>();
PageRequest pageRequest = this.getPage(request);
System.out.println(pageRequest + "=pageRequest");
// 根据工区名称查询所有井名称
if (!"".equals(workareaName) && null != workareaName) {
String str = "from Wellinfo where workArea = '" + workareaName + "'";
List<Wellinfo> wellInfoList = workareaInfoService.queryWellinfoList(pageRequest, str);
if (wellInfoList.size() > 0) {
String wellNum = "";
for (int i = 0; i < wellInfoList.size(); i++) {
wellNum = wellInfoList.get(i).getWellName();
wellIds += wellNum + ";";
}
}
}
String hql = joinHql(wellNames, workareaName);
String cyhql = "";
String zshql = "";
if (StringUtils.isNotBlank(workareaName)) {
cyhql = "from Wellinfo where wellType <> '注水井' and workArea = '" + workareaName + "'";
zshql = "from Wellinfo where wellType like '%注水%' and workArea = '" + workareaName + "'";
} else if (StringUtils.isNotBlank(wellIds)) {
cyhql = joinCyWellHql(wellIds);
zshql = joinZsWellHql(wellIds);
} else if (StringUtils.isNotBlank(wellNames)) {
cyhql = joinCyWellHqlName(wellNames);
zshql = joinZsWellHqlName(wellNames);
}
WorkareaInfoBo wibo = workareaInfoService.queryWorkareaInfo(pageRequest, hql + "@" + cyhql + "@" + zshql,
date_start, date_end, wellNames,cengwei);
String sql = "select tmcl cl ,qkzymj mj from ycab03 where qkmc = '东仁沟区'and gxsj=(select max(gxsj) gxsj from ycab03 where qkmc = '东仁沟区')";
List<AreaSeartH> ah = dataReportService.queryAreaAndChuliangServer(sql,AreaSeartH.class);
JSONObject obj = new JSONObject();
DecimalFormat df=new DecimalFormat("0.00");
if(ah.size()>0){
double yujichuliang;
double suoxuanmianji;
obj.put("dzreserves", ah.get(0).getCl());
obj.put("workarea", ah.get(0).getMj());
if(StringUtils.isNotEmpty(ah.get(0).getCl())&&StringUtils.isNotEmpty(wibo.getOilWellNum())){
yujichuliang = Double.parseDouble(ah.get(0).getCl())/1137*Double.parseDouble(wibo.getOilWellNum());
obj.put("guessGeologicla",df.format(yujichuliang));
}else{
obj.put("guessGeologicla", "0.00");
}
if(StringUtils.isNotEmpty(ah.get(0).getMj())&&StringUtils.isNotEmpty(wibo.getOilWellNum())){
suoxuanmianji = Double.parseDouble(ah.get(0).getMj())/1137*Double.parseDouble(wibo.getOilWellNum());
obj.put("calculatearea",df.format(suoxuanmianji));
}else{
obj.put("calculatearea", "0.00");
}
}else{
obj.put("dzreserves", "0.00");
obj.put("workarea", "0.00");
}
obj.put("endDate", wibo.getEndDate());
obj.put("injectWaterNum",wibo.getInjectWaterNum());
obj.put("productOilNum",wibo.getProductOilNum());
obj.put("oilWellNum",wibo.getOilWellNum());
obj.put("startDate", wibo.getStartDate());
obj.put("waterWellNum", wibo.getWaterWellNum());
obj.put("wellNames", wibo.getWellNames());
obj.put("yeliang",wibo.getYeliang()); obj.put("currcyou", wibo.getCurrcyou());
obj.put("currzshui",wibo.getCurrzshui());
obj.put("curryeliang", wibo.getCurryeliang());
response.getWriter().write(obj.toString());
response.getWriter().flush();
response.getWriter().close();
}
servlet应用具体实例的更多相关文章
- 每一个Servlet只有一个实例,多个线程
每一个Servlet只有一个实例,多个线程: Servlet: package com.stono.servlet.synchronize; import javax.servlet.http.Htt ...
- JSP+JavaBean+Servlet工作原理实例…
JSP+JavaBean+Servlet工作原理实例讲解 首先,JavaBean和Servlet虽都是Java程序,但是是完全不同的两个概念.引用mz3226960提出的MVC的概念,即M-model ...
- JSP+servlet简单登录实例
一个简单的jsp+servlet实例,实现简单的登录 转载▼ http://blog.sina.com.cn/s/blog_5c5bc9070100z7wb.html 开发环境myeclips ...
- Tomcat+Servlet登录页面实例
概念 Tomcat server是一个免费的开放源码的Web 应用server,属于轻量级应用server,在中小型系统和并发訪问用户不是非常多的场合下被普遍使用,是开发和调试JSP 程序的首选. ...
- (详细)Eclips+jsp+servlet+mysql+登录实例+源代码
欢迎任何形式的转载,但请务必注明出处. 该教程较全,从软件的安装以及相关的环境配置我都放置了相关教程的链接,读者可直接点击进入.自己写电商网站作业时查找了很多资料,但都不是很全,所以趁着寒假写了这份教 ...
- Javabean+servlet+JSP(html)实例应用
大家都知道Javabean+servlet+JSP是最简单的MVC模式.的确,在一个小型的项目中,这个模式完全够用. 它优雅并且简洁.加上jQueryui的完美展示效果,让这个模式看起来非常合适.当然 ...
- Servlet程序开发--实例操作:MVC设计模式应用
以前做过一个登录程序,是用JSP+JavaBean完成的,最大的问题,JSP文件内容太多了. 1. VO 2. DBC 3. DAO 3.1 impl 3.2 proxy 4. Factory 5. ...
- Servlet的HelloWorld实例
以下内容引用自http://wiki.jikexueyuan.com/project/servlet/first-example.html: Servlets是Java类,服务于HTTP请求并实现了j ...
- Servlet学习(三)——实例:用户登录并记录登陆次数
1.前提:在Mysql数据库下建立数据库web13,在web13下创建一张表user,插入几条数据如下: 2.创建HTML文件,命名为login,作为登录界面(以post方式提交) <!DOCT ...
随机推荐
- SQL Server DATEADD() 函数
SQL Server Date 函数 定义和用法 DATEADD() 函数在日期中添加或减去指定的时间间隔. 语法 DATEADD(datepart,number,date) date 参数是合法的日 ...
- beego 0.9.0 中智能路由AutoRouter的使用方法及源码解读
了解beego的开发者肯定知道,beego的路由设计来源于sinatra,原来是不支持自动路由的,每一个路由都要自己配置的,如: type MainController struct { beego. ...
- 复习linq
复习linq linq的英文是language integrated query.其中query的意思就是疑问或者计算机用语就是从资料库中提取信息的要求,可以理解为查询的意思.那么它翻译过来的话就是集 ...
- Android journey3 @点击事件的4种写法
对于android布局中的控件,如Button等会有相应的点击事件去响应它所需要的功能,今天我们就以电话拨号器的代码说明下几种点击事件: package com.itheima.phone; impo ...
- CodeForces 173B Chamber of Secrets 二分图+最短路
题目链接: http://codeforces.com/problemset/problem/173/B 题意: 给你一个n*m的地图,现在有一束激光从左上角往左边射出,每遇到‘#’,你可以选择光线往 ...
- 16进制串hex与ASCII字符串相互转换
提供两个函数,方便十六进制串与ASCII 字符串之间的相互转换,使用函数需要注意的是返回的串是在堆上通过 calloc 分配的,所以,记得使用完返回值释放该块,并且将指向该块的指针 =NULL . c ...
- Roy Li的学习和成长自传
我不知道自己是什么时候从哪里来到这个世界上的,也许是石头里蹦出来的,也许是女娲捏出来的,上帝造出来的.上溯到我记忆的最前端,抱着我的好象 是一个女人,穿着白衣服,白得象石灰一样的那种.以至于后来我被告 ...
- uva 10626
dp 记忆化搜索 3个1元和1个10元的情况不能少 #include <cstdio> #include <cstdlib> #include <cmath> #i ...
- Unity3D之Vector3.Dot和Vector3.Cross的使用
在unity3d中,Vector3.Dot表示求两个向量的点积;Vector3.Cross表示求两个向量的叉积. 点积计算的结果为数值,而叉积计算的结果为向量.两者要注意区别开来. 在几何数学中: 1 ...
- DataGrid行详细信息的绑定--DataGrid.RowDetailsTe(转载)
在Silverlight中的DataGrid控件使用中我们想点击其中一行并且看这一行的详细信息应该如何做呢?而且这个详细信息是多行的数据,而非简单的几个属性. 在这里我们使用DataGrid.RowD ...