搭建jetty http框架 <一>
2017-10-18 18:10
288 查看
文档参照
1 首先架构jetty,将相关包导入后
2 新建servlet
完了之后,在浏览器中输入http://localhost:8090/MyServer/helloWorld?userName=zhangsan&password=123,得到的结果如下:
hello world~~~~~~
测试中文信息:haybcp922h6x1v8bh9xeazx96
用户信息:zhangsan
用户密码:123
测试jetty安装完毕 可以连接通jetty和servlet
jetty搭建http服务器
http://blog.csdn.net/super_ninja/article/details/39692901基于Spring MVC的简单HelloWorld实例
http://blog.csdn.net/techbirds_bao/article/details/84444861 首先架构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
测试jetty安装完毕 可以连接通jetty和servlet
相关文章推荐
- eclipse中SSH三大框架环境搭建<一>
- Spring+Dubbo+Zookeeper框架搭建--<一>Zookeeper安装
- 基于Flask框架的Python web程序的开发实战 <一> 环境搭建
- spring+spring mvc + mybatis + maven 项目框架搭建笔记<一>
- eclipse中SSH三大框架环境搭建<一>
- 搭建jetty spring 框架 配置spring 注解 <二>
- struts框架知识点总结<一>
- 【Qt编程】基于Qt的词典开发系列<一>--词典框架设计及成品展示
- struts+spring+hibernate的web应用<一> 架构搭建
- Android React-Native系列之<一>零基础搭建React-Native开发环境
- Ulua热更新提高 <一> Ulua_SimpleFramework框架流程详解
- 【Qt编程】基于Qt的词典开发系列<一>--词典框架设计及成品展示
- Mac之OS系统下搭建JavaEE环境 <一> 之JDK的安装配置
- Django框架<一>
- 三大框架整合原理及详解<一>
- RecyclerView下拉刷新、上拉加载框架<一>
- Foundation框架-学习笔记<一>
- eclipse中SSH三大框架环境搭建<二>
- 搭建框架时快速找到文件的路径<xxx-class></xxx-class>
- ubuntu10.04 AVD<一> 搭建环境