Jetty实战之 嵌入式Jetty集成Spring运行
Request url: " + target + " "); response.getWriter().println("Server port: " + request.getServerPort() + " "); } } 4. 创建一个spring配置文件,并放在com/google/code/garbagecan/jettystudy/sample4/spring.xml位置,内容如下.
5. 运行MyServer类,然后通过http://localhost:8080/来访问。
发布日期:2021-06-30 18:38:30
浏览次数:2
分类:技术文章
本文共 3261 字,大约阅读时间需要 10 分钟。
原文链接:http://blog.csdn.net/kongxx/article/details/7227107
1. 首先修改pom.xml文件,添加spring的依赖项
4.0.0 com.google.code.garbagecan.jettystudy jettystudy jar 1.0-SNAPSHOT jettystudy http://maven.apache.org maven-compiler-plugin true org.eclipse.jetty.aggregate jetty-all 8.0.4.v20111024 jar provided org.springframework spring 2.5.6 jar provided junit junit 3.8.1 test
2. 创建一个Server类,用来通过spring来启动Jetty server
package com.google.code.garbagecan.jettystudy.sample4; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MyServer { public static void main(String[] args) throws Exception { new ClassPathXmlApplicationContext("/com/google/code/garbagecan/jettystudy/sample4/spring.xml"); } }3. 创建一个Handler类,用了处理http请求
package com.google.code.garbagecan.jettystudy.sample4; 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 MyHandler 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("Hello World
"); response.getWriter().println("
其中定义了Jetty Server的配置,包括Connector和Handler等等。
5. 运行MyServer类,然后通过http://localhost:8080/来访问。
转载地址:https://linqiarui.blog.csdn.net/article/details/50783597 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2024年04月08日 08时48分34秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
UVA-11538 Chess Queen(数学)
2019-04-30
UVA-11401 Triangle Counting(数学优化)
2019-04-30
Codeforces Round #369 (Div. 2)
2019-04-30
UVA 11426 GCD - Extreme (II)(欧拉函数)
2019-04-30
HDU-2838 Cow Sorting(树状数组)
2019-04-30
POJ-2299 Ultra-QuickSort(树状数组)(离散化)
2019-04-30
基于SSM的兼职论坛系统的设计与实现
2019-04-30
基于java的图书管理系统的设计与实现
2019-04-30
基于java的SSM框架理财管理系统的设计与实现
2019-04-30
基于java的ssm框架就业信息管理系统的设计
2019-04-30
基于java的ssm框架的旅游网站设计与实现
2019-04-30
基于java的SSM框架的流浪猫救助网站的设计与实现
2019-04-30
基于java的SSM框架的教务关系系统的设计与实现
2019-04-30
别再问我什么是A/B测试了!
2019-04-30
如何用同期群分析模型提升留存?(Tableau实战)
2019-04-30
爱了,吹爆这个高颜值的流程图工具!
2019-04-30
一个数据项目
2019-04-30
基于JAVA_JSP电子书下载系统
2019-04-30
基于java出租车计价器设计与实现
2019-04-30