利用jetty在浏览器上显示“hello world ” 方法2
来源:互联网 发布:面向接口编程的好处 编辑:程序博客网 时间:2024/05/21 09:27
1:新建一个类 HelloHandler
2:新建第二个类 SimplestServer
3:
import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.eclipse.jetty.server.Request;import org.eclipse.jetty.server.handler.AbstractHandler;public class HelloHandler extends AbstractHandler{ public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); response.getWriter().println("<h1>hello world</h1>"); }}
2:新建第二个类 SimplestServer
To embed a Jetty server, the following steps are typical:
1.Create the server
2.Add/Configure Connectors
3.Add/Configure Handlers
4.Add/Configure Servlets/Webapps to Handlers
5.Start the server
6.Wait (join the server to prevent main exiting)
public class SimplestServer {public static void main(String[] args) throws Exception {Server server = new Server(8080);server.setHandler(new HelloHandler());server.start();server.join();}}
3:
运行第二个jetty服务类
在浏览器上输入网址:localhost:8080
- 利用jetty在浏览器上显示“hello world ” 方法2
- 利用jetty在服务器上面显示“hello world”
- Jetty Hello World
- webpack (一) 浏览器中显示hello world
- Myeclispe 利用Servlet在浏览器中输出 hello world 的源码
- 在iPod touch上写"hello world"
- Mybatis在Maven上的 hello world
- JSF中编写一个在页面上显示的Hello World
- 利用 Masm 编写 引导盘 Boot Sector 显示 Hello World
- 《Javaweb---用自定义标签在浏览器中输出hello world!》
- JavaScript显示hello world
- input框在浏览器上显示一个叉,去掉方法
- 【laravel】用laravel在游览器中显示Hello World
- 站在巨人的肩膀上开发游戏(2) -- Orx入门引导及Hello World
- 在N-Gage上折腾一个Hello World程序
- 成功在 Tiny6410开发板上加载hello world模块
- 成功在 Tiny6410开发板上加载hello world模块
- 在 Windows Phone 上构建一个 Hello World 程序
- 离职计划中
- ExtJS Tips->Grid column的自定义格式
- 获取浏览器各种可见边框长度
- TMscomm安装及安装过程出现的问题
- GNU通用公共许可证第三版(GPLv3)翻译稿
- 利用jetty在浏览器上显示“hello world ” 方法2
- ABAP 负号 提前
- hdu 3602 2012 DP
- 如何解决ALV的负数符号前显的问题
- ASP.NET - SiteMapPath Web 服务器控件概述
- 深入浅出SharePoint——操作Item权限类
- C#中Attributes的用法
- 电子邮件30周年纪念图表
- 12家上市银行日均净赚逾23亿 利息收入以价补量