本文整理汇总了Java中javax.servlet.http.HttpServletRequest.setCharacterEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.setCharacterEncoding方法的具体用法?Java HttpServletRequest.setCharacterEncoding怎么用?Java HttpServletRequest.setCharacterEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.setCharacterEncoding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFilter
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
String target = request.getRequestURI();
if (contextPathLength != 0) {
target = target.substring(contextPathLength);
}
boolean handle = actionHandler.handle(target, request, response);
if (!handle) {// 没有处理则放行
chain.doFilter(request, response);
}
}
示例2: service
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
String method = request.getParameter("method");
if ("check".equals(method)) {
toCehck(request, response);
}
if ("query".equals(method)) {
toGetAll(request, response);
}
if ("nosignin".equals(method)) {
toGetNoSignin(request, response);
}
}
示例3: service
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8;");
String adminLogout = request.getParameter("adminLogout");
JSONObject js = new JSONObject();
if(null != adminLogout && "adminLogout".equals(adminLogout)) {
if(null != request.getSession().getAttribute("loginedAdmin"))
request.getSession().removeAttribute("loginedAdmin");
js.put("logout", "success");
response.getWriter().print(js);
} else {
js.put("logout", "fail");
response.getWriter().print(js);
}
}
示例4: dispatch
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public void dispatch(ControllerContext controllerContext)
throws ServletException, IOException, NoResourceException {
HttpServletRequest request=controllerContext.getRequest();
HttpServletResponse response=controllerContext.getResponse();
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
String URI=request.getRequestURI();
System.out.println(URI);
String actionString=URI.substring(URI.lastIndexOf("/")+1, URI.indexOf("."));
System.out.println(actionString);
ActionDescriptor matchedActionDescriptor = actionConfiguration.findMatchedAction(actionString);
controllerContext.setActionDescriptor(matchedActionDescriptor);
String resultString="";
if(matchedActionDescriptor ==null){//didn't find this action in configuration file
throw new NoResourceException("matched ActionDescriptor is null.");
}else {
resultString = useProxy(controllerContext);
}
if(controllerContext.getResultDescriptor()==null)
controllerContext.setResultDescriptor(resultString);
}
示例5: doPost
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
if (req.getRequestURI().endsWith("parseParametersBeforeParseParts")) {
req.getParameterNames();
}
req.getPart("part");
resp.setContentType("text/plain");
resp.setCharacterEncoding("UTF-8");
resp.getWriter().println("Part " + req.getParameter("part"));
}
示例6: service
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8;");
String gameUserLogout = request.getParameter("gameUserLogout");
JSONObject js = new JSONObject();
if(null != gameUserLogout && "gameUserLogout".equals(gameUserLogout)) {
if(null != request.getSession().getAttribute("loginedGameUser"))
request.getSession().removeAttribute("loginedGameUser");
js.put("logout", "success");
response.getWriter().print(js);
} else {
js.put("logout", "fail");
response.getWriter().print(js);
}
}
示例7: preHandle
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
HttpSession session = request.getSession();
if (!"".equals(session.getAttribute(Constant.USERNAME))&& session.getAttribute(Constant.USERNAME)!=null && !"".equals(session.getAttribute(Constant.TOKEN)) && session.getAttribute(Constant.TOKEN)!=null ) {
return true;
} else {
PrintWriter out;
out = response.getWriter();
String json;
Gson gson = new Gson();
Message<String> message = new Message<String>("-200","管理员未登录,请重新登录","");//初始化message对象
json = gson.toJson(message, Message.class); //使用gson将Message对象转化为字符串
out.print(json);
return false;
}
}
示例8: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//�����ַ�����ʽ
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
//���Ȼ�ÿͻ��˷����������(keyword)
String keyword1 = req.getParameter("keyword");
String keyword = Escape.unescape(keyword1);
//��ùؼ���֮����д��?�õ��������
List<String> listData = getData(keyword);
// System.out.println(JSONArray.fromObject(listData));
// JSONArray.fromObject(listData);
//����json��ʽ
resp.getWriter().write(JSONArray.fromObject(listData).toString());
}
示例9: entrust
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* 请求委托
* @param request
* @param response
* @param httpServlet
*/
public void entrust(HttpServletRequest request, HttpServletResponse response, HttpServlet httpServlet){
method = request.getMethod();
this.request = request;
response.setCharacterEncoding(encode);
//设置POST请求的字符编码
if(method.equals("POST")){
try {
request.setCharacterEncoding(encode);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
//设置Content-Type
response.setHeader("Content-Type", "text/html;charset=" + encode);
execute(request, response, httpServlet);
}
示例10: getDownloadImagesHistory
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* 历史导出列表
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping(value = "/admin/getdownloadimageshistory", method = RequestMethod.POST)
public void getDownloadImagesHistory(HttpServletResponse response, @RequestParam("start") String start,
@RequestParam("page_num") String page_size, HttpServletRequest request) throws IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8"); // 设置响应responce编码为utf-8
PrintWriter out = response.getWriter();
SplitObject<ExportHistoryLabel> splitObject = new SplitObject<ExportHistoryLabel>();
String json;
Gson gson = new Gson();
// 获取所有历史列表
List<ExportHistoryLabel> exportHistoryLabels = exportService.gExportHistoryLabels(Integer.parseInt(start),
Integer.parseInt(page_size));
// 获取历史列表数量
int num = new Long(exportService.exportHistoryLabelsNum()).intValue();
splitObject.setList(exportHistoryLabels);
if (num % Constant.DEVI_NUM == 0) {
splitObject.setPages_num(num / Constant.DEVI_NUM);
} else {
splitObject.setPages_num((num / Constant.DEVI_NUM + 1));
}
Message<SplitObject<ExportHistoryLabel>> message = new Message<SplitObject<ExportHistoryLabel>>("200", "",
splitObject);// 初始化message对象
json = gson.toJson(message, Message.class); // 使用gson将Message对象转化为字符串
out.print(json);
}
示例11: doFilter
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
req.setCharacterEncoding(this.encoding);
if (this.forceEncoding) {
res.setCharacterEncoding(this.encoding);
}
chain.doFilter(req, res);
}
示例12: doPost
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setCharacterEncoding("UTF-8");
req.setCharacterEncoding("UTF-8");
getHeadersInfo(req);
routeByHeader(req);
String retJson = "hello i'm running... server time: " + TimeUtil.msec2date(System.currentTimeMillis()) + " ,version " + Params.versionName;
PrintWriter writer = resp.getWriter();
writer.write(retJson);
writer.flush();
writer.close();
}
示例13: processAction
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Process current get or post request.
*
* @param req Http servlet request.
* @param resp Http servlet response.
* @throws ServletException If the request could not be handled.
* @throws IOException If an input or output error is detected.
*/
private void processAction(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
req.getSession().setAttribute("register", Boolean.FALSE);
if (req.getParameter("action") != null) {
checkLoginParameters(req);
} else {
req.getSession().setAttribute("error", false);
}
List<BlogUser> users = DAOProvider.getDAO().getAllUsers();
req.setAttribute("users", users);
req.getRequestDispatcher("/WEB-INF/pages/Index.jsp").forward(req, resp);
}
示例14: service
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//设置request和response的编码格式
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8;");
String userName = request.getParameter("username");
String userId = request.getParameter("id");
String userPhone = request.getParameter("phone");
String userEmail = request.getParameter("email");
String userPassword = request.getParameter("pwd");
String serverId = request.getParameter("area");
System.out.println("{" + userName + ";"+ userId + ";"+ userPhone +";" + userEmail + ";"+ serverId +"}");
// 得到验证码输入框中的验证码的值
String chkCode = request.getParameter("chkcode");
// 获得session对象
HttpSession session = request.getSession();
// 得到session中验证码的值
String tmpCode = (String) session.getAttribute("checkcode");
System.out.println("老子的注册servlet被调戏了QAQ");
//验证码的比较结果
boolean flag = tmpCode.equals(new String(chkCode).toLowerCase());
if(!flag){
response.sendRedirect("/GameProject/jsp/regist.jsp?time=" + new java.util.Date().getTime());
}
//注册失败,跳转到registFailed页面
boolean flag1 = guDao.gameUserRegist(userName, userId, userPhone, userEmail, userPassword, serverId);
if(!flag1) {
response.sendRedirect("/GameProject/userjsp/registFailed.jsp");
}
//注册成功,利用session代理该对象的数据
GameUser gu = new GameUser();
gu.setServerId(serverId);
gu.setUserName(userName);
gu.setUserPassword(userPassword);
if(null == session.getAttribute("loginedGameUser") &&
null == session.getAttribute("autoLogin"))//session为空时,说明时第一次登陆,将数据加入session代理
session.setAttribute("loginedGameUser", gu);//session代理该gameuser对象
session.setAttribute("autoLogin", "no");//注册成功默认是不自动登录
//注册成功,跳转到registSuccess页面
response.sendRedirect("/GameProject/userjsp/registSuccess.jsp");
}
示例15: doPost
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
HttpSession s = request.getSession();
s.removeValue("user_id");
s.invalidate();
response.sendRedirect("login.jsp");
}