Android 开发服务类 03_ServletForGETMethod
接收并处理用户通过 GET 方式上传的数据,一般小于 2K,并且安全性要求不高。
package com.wangjialin.internet.servlet; import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; @WebServlet("/ServletForGETMethod")
public class ServletForGETMethod extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name= request.getParameter("name");
// String name= new String(request.getParameter("name").getBytes("ISO8859-1"),"UTF-8");
String age= request.getParameter("age");
System.out.println("name: " + name );
System.out.println("age: " + age ); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
} }
HttpServletRequestEncodingWrapper (HttpServletRequest 业务包装器,解决汉字乱码的问题)
package com.wangjialin.internet.filter; import java.io.UnsupportedEncodingException; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper; public class HttpServletRequestEncodingWrapper extends
HttpServletRequestWrapper { private HttpServletRequest request;
public HttpServletRequestEncodingWrapper(HttpServletRequest request) {
super(request);
this.request = request;
} @Override
public String getParameter(String name) { String value = request.getParameter(name);
try {
if(value != null){
return new String(value.getBytes("ISO8859-1"), "UTF-8");
}
} catch (UnsupportedEncodingException e) {
}
return super.getParameter(name);
} }
EncodingFilter
package com.wangjialin.internet.filter; 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.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest; @WebFilter("/*")
public class EncodingFilter implements Filter { public void destroy() {
// TODO Auto-generated method stub
} public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; if("GET".equals(req.getMethod())){ HttpServletRequestEncodingWrapper wraper = new HttpServletRequestEncodingWrapper(req);
chain.doFilter(wraper, response); }else{
req.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
} public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
}
}
Android 开发服务类 03_ServletForGETMethod的更多相关文章
- Android 开发服务类 05_ ApkPatchDemo
APP 增量更新服务端[https://github.com/cundong/SmartAppUpdates] import com.cundong.common.Constants; import ...
- Android 开发服务类 04_ServletForPOSTMethod
ServletForPOSTMethod 业务类 package com.wangjialin.internet.servlet; import java.io.IOException; import ...
- Android 开发服务类 02_NewsListServlet
Servlet implementation class NewsListServlet package com.wangjialin.server.xml; import java.io.IOExc ...
- Android 开发服务类 01_ServletForXML
Servlet implementation class NewsListServlet package com.wangjialin.server.xml; import java.io.IOExc ...
- Android开发工具类
7种无须编程的DIY开发工具 你知道几个? 现如今,各种DIY开发工具不断的出现,使得企业和个人在短短几分钟内就能完成应用的创建和发布,大大节省了在时间和资金上的投入.此外,DIY工 具的出现,也帮助 ...
- Android开发——Context类的各种细节问题
0. 前言 Context相信所有的Android开发人员基本上每天都在接触,因为它太常见了.但实际上Context有太多小的细节并不被大家所关注,那么今天我们就来学习一下那些你所不知道的细节. ...
- Android 开发工具类 35_PatchUtils
增量更新工具类[https://github.com/cundong/SmartAppUpdates] import java.io.File; import android.app.Activity ...
- Android 开发 Camera类的拍照与录像
前言 在开发Android应用的时候,如果需要调用摄像头拍照或者录像,除了通过Intent调用系统现有相机应用进行拍照录像之外,还可以通过直接调用Camera硬件去去获取摄像头进行拍照录像的操作.本篇 ...
- Android 开发工具类 27_多线程下载大文件
多线程下载大文件时序图 FileDownloader.java package com.wangjialin.internet.service.downloader; import java.io.F ...
随机推荐
- Oracle之SQL语句性能优化(34条优化方法)
(1)选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最先处 ...
- MongoDB安装为Windows服务方法与注意事项
MongoDB作为一个基于分布式文件存储的数据库,近两年大受追捧.数据灵活的存取方式和高效的处理使得它广泛用于互联网应用. 最近本人开始在Windows 32位平台下研究MongoDB的使用,为了方便 ...
- (线段树)敌兵布阵--hdu--1166 (入门)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1166 自己第一次在没有看题解AC出来的线段树,写的可能不是太好,再贴个学长的代码,学习一下 发现自己的U ...
- linux信号量(转载)
本文转载自http://blog.csdn.net/qinxiongxu/article/details/7830537 信号量一.什么是信号量信号量的使用主要是用来保护共享资源,使得资源在一个时刻只 ...
- hdu 5025 bfs+状压
http://acm.hdu.edu.cn/showproblem.php?pid=5025 N*N矩阵 M个钥匙 K起点,T终点,S点需多花费1点且只需要一次,1-9表示9把钥匙,只有当前有I号钥匙 ...
- handsontable 问题
碰到问题了,去官网上找community:http://docs.handsontable.com/0.16.1/tutorial-quick-start.html 1. 描述:把handson ta ...
- plsql高版本无法设置Fixedsys字体解决办法(win7&winXP适用)
http://hi.baidu.com/crsky2008/item/c174c9fb52577919e3e3bd6b 设置如下:Tools->Preferences->Oracle-&g ...
- Java子父类中的构造函数实例化过程
其实我们发现子类继承父类操作很简单,如果要是去深入的研究下会发现,实例化过程并非是我们看到的那样,我们就以代码举例来说明: 问大家,以下代码执行会输出什么呢? package com.oop; /** ...
- [Ubuntu]管理开机启动项的软件
sudo apt-get install sysv-rc-conf
- 开源WebGIS实施方案(六):空间数据(PostGIS)与GeoServer服务迁移
研发环境的变更,或者研发完成进行项目现场实施.运维的时候,经常就会面临数据及服务的迁移,这其中就包含空间数据以及GeoServer服务的迁移工作. 这里需要提醒的是:如果采用的是类似的开源WebGIS ...