搭建jetty http框架 <一>
来源:互联网 发布:java调用com组件 编辑:程序博客网 时间:2024/05/16 18:11
文档参照
jetty搭建http服务器
http://blog.csdn.net/super_ninja/article/details/39692901
基于Spring MVC的简单HelloWorld实例
http://blog.csdn.net/techbirds_bao/article/details/8444486
1 首先架构jetty,将相关包导入后
public class ServerMain { private static final String CONFIG_LOCATION = "com.easysoft.cn.config"; private static final String MAPPING_URL = "/*"; private static final String DEFAULT_PROFILE = "dev"; public static void main(String[] args) throws Exception { Server server = new Server(8090); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/MyServer"); //这里是请求的上下文,比如http://localhost:8090/MyServer server.setHandler(context); WebApplicationContext applicationContext=getContext();// context.addServlet(new ServletHolder(new HelloWorld()), "/helloWorld"); //添加servlet,第一是具体的servlet,后面是请求的别名,在http请求中的路径// context.addServlet(new ServletHolder(new HelloWorld("chan")), "/HellworldWithParams");// context.addServlet(new ServletHolder(new DispatcherServlet( applicationContext)), MAPPING_URL);// context.addEventListener(new ContextLoaderListener(applicationContext));// context.setResourceBase(new ClassPathResource("webapp").getURI().toString()); server.start(); server.join(); }
2 新建servlet
public class HelloWorld extends HttpServlet { /** * serialVersionUID */ private static final long serialVersionUID = 2271797150647771294L; private String msg = "hello world~~~~~~"; public HelloWorld() { } public HelloWorld(String msg){ this.msg = msg; } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String userName = req.getParameter("userName"); String password = req.getParameter("password"); resp.setCharacterEncoding("UTF-8"); resp.setContentType("text/html"); resp.setStatus(HttpServletResponse.SC_OK); PrintWriter pWriter = resp.getWriter(); pWriter.println("<h1>" + msg + "</h1>"); pWriter.println("测试中文信息:" + req.getSession(true).getId()); pWriter.println("<h3>用户信息:" + userName + "</h3>"); pWriter.println("<h3>用户密码:" + password + "</h3>"); }}
完了之后,在浏览器中输入http://localhost:8090/MyServer/helloWorld?userName=zhangsan&password=123,得到的结果如下:
- hello world~~~~~~
- 测试中文信息:haybcp922h6x1v8bh9xeazx96
- 用户信息:zhangsan
- 用户密码:123
阅读全文
0 0
- 搭建jetty http框架 <一>
- jetty搭建http服务器
- SpringMVC+jetty框架搭建
- 【Jetty Server 开发系列之一】搭建Jetty Server环境&&Http客户端实现交互
- JAVA基本框架搭建(Maven,jetty,Joda-time,junit)
- JAVA基本框架搭建(Maven,jetty,Jod…
- 搭建jetty spring 框架 配置spring 注解 <二>
- ThinkPHP框架一 框架搭建
- 框架搭建一
- 基础框架搭建(一)
- Jetty 一
- 搭建IntelliJ IDEA+maven+jetty+SpringMVC 开发环境(一)
- 搭建IntelliJ IDEA+maven+jetty+SpringMVC 开发环境(一)
- jetty HTTP长连接
- apache camel jetty http
- springMVC3学习(一)--框架搭建
- 一、springMVC+freemarker框架搭建
- springMVC3学习(一)--框架搭建
- SegNet-基于深度学习的图像分割
- VS2015+opencv-3.2.0环境配置
- 身份证号码工具类
- JsonCpp如何判断是否有某个KEY
- 关于easyui中默认给FORM赋值的错误
- 搭建jetty http框架 <一>
- 51 nod 质数中的质数
- 【Docker】Docker学习笔记:shipyard使用
- 第一单元
- Json简介
- Android App打开手机QQ、微信等应用
- 关于git reset --hard导致文件丢失的血的教训
- 排序算法的java实现-归并排序
- TCP 的那些事儿(上)