本文整理匯總了Java中javax.servlet.http.HttpServletResponse.setCharacterEncoding方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.setCharacterEncoding方法的具體用法?Java HttpServletResponse.setCharacterEncoding怎麽用?Java HttpServletResponse.setCharacterEncoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.setCharacterEncoding方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doPost
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.setBufferSize(8192);
switch (Integer.parseInt(request.getParameter("case")))
{
case 1 : getServletContext().getRequestDispatcher("/entryreview.jsp").forward(request,response);
return;
case 2 : getServletContext().getRequestDispatcher("/place_entry.jsp").forward(request,response);
return;
case 3 : getServletContext().getRequestDispatcher("/updatemobno.jsp").forward(request,response);
return;
case 4 : getServletContext().getRequestDispatcher("/updatepassword.jsp").forward(request,response);
return;
case 5 : getServletContext().getRequestDispatcher("/updateemail.jsp").forward(request,response);
return;
default : request.setAttribute("uid", request.getParameter("uid"));
getServletContext().getRequestDispatcher("/successlogin.jsp").forward(request,response);
return;
}
}
示例2: page
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public void page(HttpServletResponse response, int statusCode, String title, String message) throws IOException {
title = htmlEncode(title);
message = htmlEncode(message);
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8"));
out.println("<html>");
out.println("<head><title>" + title + "</title></head>");
out.println("<body>");
out.println("<h2>" + title + "</h2>");
out.println("<p>" + message + "</p>");
out.println("</body>");
out.println("</html>");
out.flush();
response.setStatus(statusCode);
}
示例3: render
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private static void render(HttpServletResponse response, String text) {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0L);
PrintWriter pw = null;
try{
pw = response.getWriter();
pw.write(text);
} catch (IOException var8) {
var8.printStackTrace();
} finally {
pw.close();
}
}
示例4: queryUserByPost
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* @note 獲取崗位下的所有用戶
* @param postId 崗位ID
* @return IUser[]
*/
@RequestMapping("/queryUserByPost")
public void queryUserByPost(HttpServletRequest request, HttpServletResponse response)
{
MyRequest req = new MyRequest(request);
String systemAlias = req.getString("name");
String pwd = req.getString("pwd");
String postId = req.getString("postId");
try
{
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain;charset=UTF-8");
PrintWriter out = response.getWriter();
if(isSystemCheck(systemAlias, pwd))
{
IUser[] m = service.queryUserByPostid(postId);
out.print(toJson(m));
}
out.print("");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
示例5: popupQrImageUpdateSubmit
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* 通用電腦模式,更改底部的二維碼,提交保存
*/
@RequestMapping(value = "popupQrImageUpdateSubmit")
public void popupQrImageUpdateSubmit(Model model,HttpServletRequest request,HttpServletResponse response,
@RequestParam("qrImageFile") MultipartFile multipartFile) throws IOException{
JSONObject json = new JSONObject();
Site site = getSite();
if(!(multipartFile.getContentType().equals("image/pjpeg") || multipartFile.getContentType().equals("image/jpeg") || multipartFile.getContentType().equals("image/png") || multipartFile.getContentType().equals("image/gif"))){
json.put("result", "0");
json.put("info", "請傳入jpg、png、gif格式的二維碼圖");
}else{
//格式轉換
BufferedImage bufferedImage = ImageUtil.inputStreamToBufferedImage(multipartFile.getInputStream());
BufferedImage tag = ImageUtil.formatConversion(bufferedImage);
BufferedImage tag1 = ImageUtil.proportionZoom(tag, 400);
//上傳
AttachmentFile.put("site/"+site.getId()+"/images/qr.jpg", ImageUtil.bufferedImageToInputStream(tag1, "jpg"));
AliyunLog.addActionLog(getSiteId(), "通用電腦模式,更改底部的二維碼,提交保存");
json.put("result", "1");
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter out = null;
try {
out = response.getWriter();
out.append(json.toString());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
}
}
示例6: run
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public void run(String serviceName, HttpServletRequest request, HttpServletResponse response) throws ServiceException {
try {
// Create the document XML response
Document document = DOMUtils.createDocument();
Element adminElement = document.createElement("admin");
adminElement.setAttribute("service", serviceName);
document.appendChild(adminElement);
// Run the core service
getServiceResult(request, document);
// Update servlet response and write result
response.setContentType(MimeType.TextXml.value());
response.setCharacterEncoding("UTF-8");
Writer writer = response.getWriter();
XMLUtils.prettyPrintDOMWithEncoding(document, "UTF-8", writer);
if (Engine.logAdmin.isDebugEnabled()) {
String xml = XMLUtils.prettyPrintDOM(document);
Engine.logAdmin.debug("XML generated:\n" + xml);
}
}
catch (Throwable t) {
ServiceUtils.handleError(t, response);
}
}
示例7: getAllTaskFinished
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* 得到完成未完成的圖片任務
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping(value = "/admin/getalltaskfinished", method = RequestMethod.POST)
public void getAllTaskFinished(HttpServletResponse response, HttpServletRequest request) throws IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8"); // 設置響應responce編碼為utf-8
PrintWriter out = response.getWriter();
String json;
Gson gson = new Gson();
AssignImageLabel assign = new AssignImageLabel();
long unfinishedAmount = imageService.getAmountOfDefinedImage(0);
long finishedAmount = imageService.getAmountOfDefinedImage(1);
assign.setAll_img_amount((unfinishedAmount + finishedAmount) + "");
assign.setFinished_img(finishedAmount + "");
assign.setUnfinished_img(unfinishedAmount + "");
Message<AssignImageLabel> message = new Message<AssignImageLabel>("200", "", assign);// 初始化message對象
json = gson.toJson(message, Message.class); // 使用gson將Message對象轉化為字符串
out.print(json);
}
示例8: execute
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method=retriveMethod(req);
if(method!=null){
invokeMethod(method, req, resp);
}else{
VelocityContext context = new VelocityContext();
context.put("contextPath", req.getContextPath());
String file=req.getParameter("file");
String project = buildProjectNameFromFile(file);
if(project!=null){
context.put("project", project);
}
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
Template template=ve.getTemplate("html/ul-editor.html","utf-8");
PrintWriter writer=resp.getWriter();
template.merge(context, writer);
writer.close();
}
}
示例9: setLocale
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* Returns the serialized XML of the Mindmap Nodes from Database
*
* @param mapping
* @param form
* @param request
* @param response
* @return null
*/
public ActionForward setLocale(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
try {
response.setContentType("text/xml");
response.setCharacterEncoding("utf-8");
response.getWriter().write(mindmapService.getLanguageXML());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例10: doPost
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* Passes a POST request to the dispatcher.
*
* @throws IOException
* if an input or output error is detected when the servlet
* handles the request
* @throws ServletException
* if the request for the POST could not be handled
*/
@Override
protected void doPost(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
UploadResponse uploadResponse = null;
try {
ThreadLocalData.beginRequest(request);
uploadResponse = dispatcher.doPost(request);
} catch (Exception e) {
throw new ServletException(e);
} finally {
/*
* call this method to prevent detached requests or else the request
* will probably never be garbage collected and will fill your
* memory
*/
ThreadLocalData.endRequest();
}
out.print(uploadResponse);
out.flush();
out.close();
}
示例11: doFilter
import javax.servlet.http.HttpServletResponse; //導入方法依賴的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: doFilter
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain filterChain) throws IOException, ServletException {
//如果沒有驗證通過,那麽就把請求轉發到login.html
HttpServletResponse httpServletResponse = (HttpServletResponse) resp;
HttpServletRequest httpServletRequest = (HttpServletRequest) req;
httpServletRequest.setCharacterEncoding("UTF-8");
httpServletResponse.setCharacterEncoding("UTF-8");
switch(httpServletRequest.getRequestURI()){
case "/":
if(AuthConfig.isContinueLockMain()){
httpServletResponse.sendRedirect("/login.html");
}else{
httpServletResponse.sendRedirect("/index.html");
}
break;
case "/index.html":
if(AuthConfig.isContinueLockMain()){
httpServletResponse.sendRedirect("/login.html");
}else{
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
break;
default:
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
}
示例13: cpu
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@RequestMapping("/cpu")
@ResponseBody
public void cpu(HttpServletResponse response) throws IOException {
String aa = JMXClient.getInstance().getCpuUsage();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write(aa);
}
示例14: writeResponse
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public void writeResponse(HttpServletRequest request, HttpServletResponse httpResponse, Response jaxbResponse) {
String format = getStringParameter(request, "f", "xml");
String jsonpCallback = request.getParameter("callback");
boolean json = "json".equals(format);
boolean jsonp = "jsonp".equals(format) && jsonpCallback != null;
Marshaller marshaller;
if (json) {
marshaller = createJsonMarshaller();
httpResponse.setContentType("application/json");
} else if (jsonp) {
marshaller = createJsonMarshaller();
httpResponse.setContentType("text/javascript");
} else {
marshaller = createXmlMarshaller();
httpResponse.setContentType("text/xml");
}
httpResponse.setCharacterEncoding(StringUtil.ENCODING_UTF8);
try {
StringWriter writer = new StringWriter();
if (jsonp) {
writer.append(jsonpCallback).append('(');
}
marshaller.marshal(new ObjectFactory().createSubsonicResponse(jaxbResponse), writer);
if (jsonp) {
writer.append(");");
}
httpResponse.getWriter().append(writer.getBuffer());
} catch (JAXBException | IOException x) {
LOG.error("Failed to marshal JAXB", x);
throw new RuntimeException(x);
}
}
示例15: doPost
import javax.servlet.http.HttpServletResponse; //導入方法依賴的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();
}