當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletRequest.setCharacterEncoding方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:Xlongshu,項目名稱:EasyController,代碼行數:20,代碼來源:ActionDispatcherFilter.java

示例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);
	}
}
 
開發者ID:sivanWu0222,項目名稱:Registration,代碼行數:17,代碼來源:UserServlet.java

示例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);
   	}
   	
}
 
開發者ID:UnicornWebbChen,項目名稱:GameProject-V1.0Beta,代碼行數:23,代碼來源:AdminLogoutServlet.java

示例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);
}
 
開發者ID:Hang-Hu,項目名稱:SimpleController,代碼行數:22,代碼來源:RequestDispatcher.java

示例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"));
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:17,代碼來源:TestRequest.java

示例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);
   	}
   	
}
 
開發者ID:UnicornWebbChen,項目名稱:GameProject-V1.0Beta,代碼行數:23,代碼來源:GameUserLogoutServlet.java

示例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;
	}
		
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:21,代碼來源:AdminInterceptor.java

示例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());
	}
 
開發者ID:LuJiangLin,項目名稱:TestDemo1-github,代碼行數:18,代碼來源:searchAjax.java

示例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);
}
 
開發者ID:landriesnidis,項目名稱:PCloud_Server_v3,代碼行數:26,代碼來源:BaseServletAction.java

示例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);
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:36,代碼來源:AdminController.java

示例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);
}
 
開發者ID:skeychen,項目名稱:dswork,代碼行數:11,代碼來源:CharacterEncodingFilter.java

示例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();
}
 
開發者ID:lucid-lynxz,項目名稱:Webhook_server,代碼行數:13,代碼來源:ApiServlet.java

示例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);
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:23,代碼來源:HomepageServlet.java

示例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");
}
 
開發者ID:UnicornWebbChen,項目名稱:GameProject-V1.0Beta,代碼行數:55,代碼來源:GameUserRegistServlet.java

示例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");
}
 
開發者ID:yanhanwen,項目名稱:DrugStoreManagement,代碼行數:10,代碼來源:ClearServlet.java


注:本文中的javax.servlet.http.HttpServletRequest.setCharacterEncoding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。