package org.operamasks.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import org.operamasks.data.TreeNode;
import org.operamasks.data.TreeNodeService; public class OmTreeServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
doPost(request, response);
} @Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
String method = request.getParameter("method");
String content = request.getParameter("content");
if("position".equals(method)){
getPositon(request, response);
}else if("children".equals(content)){
getChildren(request, response);
}else if("simpleModel".equals(method)){
getSimpleModel(request, response);
}
else{
PrintWriter writer = response.getWriter();
String result =
"["+
"{\"text\": \"Folder 1\"," +
"\"expanded\": true," +
"\"children\":" +
"[" +
"{"+
"\"text\": \"file 1.1\"" +
"}," +
"{" +
"\"text\": \"file 1.2\"" +
"}" +
"]" +
"}," +
"{" +
"\"text\": \"Folder 2\"," +
"\"hasChildren\": true" +
"}," +
"{" +
"\"text\": \"file 3\"" +
"}" +
"]";
writer.write(result.toString());
writer.flush();
}
} private void getSimpleModel(HttpServletRequest request,
HttpServletResponse response) throws IOException {
// TODO Auto-generated method stub
PrintWriter writer = response.getWriter();
TreeNodeService service =new TreeNodeService();
List<TreeNode> nodes = service.getNodes();
writer.write(JSONArray.fromObject(nodes).toString()); } private void getChildren(HttpServletRequest request,
HttpServletResponse response) throws IOException {
PrintWriter writer = response.getWriter();
String result =
"["+
"{\"text\": \"file 2.1\"" +
"}," +
"{\"text\": \"file 2.2\"" +
"}" +"]";
writer.write(result.toString());
writer.flush();
} private void getPositon(HttpServletRequest request,
HttpServletResponse response) throws IOException {
PrintWriter writer = response.getWriter();
String result =
"["+
"{\"text\": \"研发\"," +
"\"expanded\": true," +
"\"children\":" +
"[" +
"{"+
"\"text\": \"开发平台部\"," +
"\"children\":" +
"[" +
"{"+
"\"text\": \"部门经理\"" +
"}," +
"{" +
"\"text\": \"产品经理\"" +
"}," +
"{"+
"\"text\": \"开发工程师\"" +
"}" +
"]" +
"}," +
"{" +
"\"text\": \"基础平台部\"," +
"\"children\":" +
"[" +
"{"+
"\"text\": \"部门经理\"" +
"}," +
"{" +
"\"text\": \"产品经理\"" +
"}," +
"{"+
"\"text\": \"开发工程师\"" +
"}" +
"]" +
"}," +
"{"+
"\"text\": \"工具平台部\"," +
"\"children\":" +
"[" +
"{"+
"\"text\": \"部门经理\"" +
"}," +
"{" +
"\"text\": \"产品经理\"" +
"}," +
"{"+
"\"text\": \"开发工程师\"" +
"}" +
"]" +
"}," +
"{" +
"\"text\": \"测试部\"," +
"\"children\":" +
"[" +
"{"+
"\"text\": \"部门经理\"" +
"}," +
"{" +
"\"text\": \"测试人员\"" +
"}" +
"]" +
"}" +
"]" +
"}," +
"{" +
"\"text\": \"销售\"," +
"\"expanded\": true," +
"\"children\":" +
"[" +
"{"+
"\"text\": \"销售总监\"" +
"}," +
"{" +
"\"text\": \"市场分析员\"" +
"}," +
"{"+
"\"text\": \"销售人员\"" +
"}" +
"]" +
"}," +
"{" +
"\"text\": \"人事\"," +
"\"expanded\": true," +
"\"children\":" +
"[" +
"{"+
"\"text\": \"人力资源总监\"" +
"}," +
"{" +
"\"text\": \"薪酬管理员\"" +
"}," +
"{"+
"\"text\": \"招聘人员\"" +
"}" +
"]" +
"}" +
"]";
writer.write(result.toString());
writer.flush(); } }

java 请求响应乱码的更多相关文章

  1. 中文乱码问题(页面乱码,eclipse乱码,请求响应乱码)

    1.首先在开发工具eclipse中设置工作空间和文件编码格式,详情参见   http://www.cnblogs.com/lixiang1993/p/7345161.html 2.在eclipse的安 ...

  2. SpringMVC 请求/响应乱码问题解决方案

    请求乱码解决之get乱码问题 GET请求乱码原因分析 GET请求参数是通过请求行中的URL发送给Web服务器(Tomcat)的. Tomcat服务器会对URL进行编码操作(此时使用的是Tomcat设置 ...

  3. Java中关于Servlet中请求中文乱码及文件下载

    1,Servlet请求响应中文乱码问题 package com.demo.servlet; import java.io.PrintWriter; import java.io.IOException ...

  4. Katalon Studio之请求响应中文乱码解决方法

    最近在用Katalon做接口测试过程中发现请求响应消息中返回的中文均为乱码,这是因为我们使用的系统环境在初始安装时选择的中文简体,导致windows系统默认编码格式为GBK,但是KS的编码格式是UTF ...

  5. Charles_N:HTTP请求响应监听工具

    Charles:HTTP请求响应监听工具使用说明.doc   1.    介绍 Charles是一个HTTP代理服务器,HTTP监视器,反转代理服务器.它允许一个开发者查看所有连接互联网的HTTP通信 ...

  6. java 请求 google translate

    // */ // ]]> java 请求 google translate Table of Contents 1. 使用Java获取Google Translate结果 1.1. 开发环境设置 ...

  7. Web请求响应简单整理

      简单对Web请求响应如何处理进行的整理,难免有理解不到位,理解有偏差的地方,如有理解有误的地方,希望大牛批评指正. 1.Web开发的定义首先看看微软对Web开发的定义:Web开发是一个指代网页或网 ...

  8. jmeter之自定义java请求性能测试

    一.环境准备         1.新建一个java工程         2.导入jar包:ApacheJMeter_core.jar     ApacheJMeter_java.jar         ...

  9. jmeter java请求

    demo下载地址http://yun.baidu.com/share/link?shareid=4277735898&uk=925574576 1.引用jmeter的jar包 到jmeter的 ...

随机推荐

  1. ThinkPHP框架下基于RBAC的权限控制模式详解

    这几天因为要做一个项目,需要可以对Web应用中通用功能进行封装,其中一个很重要的涉及到了对用户.角色和权限部分的灵活管理.所以基于TP框架自己封装了一个对操作权限和菜单权限进行灵活配置的可控制模式. ...

  2. Sass使用教程

    sass官网: http://sass-lang.com/ http://sass-lang.com/documentation/file.SASS_REFERENCE.html Sass和Scss的 ...

  3. Thrift入门 (一)

    Install Go to thrift page download thrift. 1 2 3 4 brew install boost ./configure --without-python s ...

  4. 优雅智慧女性课程班 - 公开课程 - 课程介绍 - 中国人民大学商学院EDP中心

    优雅智慧女性课程班 - 公开课程 - 课程介绍 - 中国人民大学商学院EDP中心 优雅智慧女性课程班 课程总览 思想睿智成熟,外表美丽自信,气质优雅端庄,是魅力女性所应具备的特性.在当今不确定环境下, ...

  5. Struts2之自定义局部类型转换器、全局类型转换器

    Struts2自定义类型转换器分为局部类型转换器和全局类型转换器 (1)局部类型转换器  如果页面传来一个参数reg.action?birthday=2010-11-12到后台action,然后属性用 ...

  6. uva 10004 Bicoloring(dfs二分染色,和hdu 4751代码差不多)

    Description In the ``Four Color Map Theorem" was proven with the assistance of a computer. This ...

  7. 关于oracle的certview

    前两天去参加oracle  11g  的两门考试(1Z0-051和1Z0-052),在家看了好几遍题库,我本来想着上午一门,下午考一门,但是我嫌着麻烦,就预约一下午考完两门.在考试完一门后,发现成绩不 ...

  8. javascript高级知识分析——实例化

    代码信息来自于http://ejohn.org/apps/learn/. new做了什么? function Ninja(){ this.name = "Ninja"; } var ...

  9. nginx 几个参数

    worker_processes : When set to 'auto', which is also the default behavior, Tengine will create the s ...

  10. QF——iOS代理模式

    iOS的代理模式: A要完成某个功能,它可以自己完成,但有时出于一些原因,不方便自己完成.这时A可以委托B来帮其完成此功能,即由B代理完成.但是这个功能不是让B随随便便任其完成.此时,会有一个协议文件 ...