设为首页 收藏本站
查看: 1580|回复: 0

[经验分享] netty 配置 jsp

[复制链接]

尚未签到

发表于 2017-2-28 07:22:39 | 显示全部楼层 |阅读模式
这个是http://www.codeproject.com/Articles/128145/Run-Jetty-Web-Server-Within-Your-Application上的描述

Introduction
  The purpose of this article is to give you a quick idea of how to build and deploy your web application without really running a web server outside your application and without creating a WAR file for the deployment. At present, I am working on a project which is a background calculation engine and it provides a simple web interface for the support and business users to monitor the ongoing activities. While deploying our application, we just start Jetty web server within our application and we can access the web application easily.
  If you visit the Jetty wiki, it is mentioned that Jetty has a slogan, "Don't deploy your application in Jetty, deploy Jetty in your application." In this article, we illustrate this slogan in a nice and simple application.
  以下是我自己的实现:
  1、项目结构如下:
DSC0000.jpg

  2、/WEB-INF/web.xml配置


DSC0001.gif DSC0002.gif web.xml配置


1 <?xml version="1.0" encoding="ISO-8859-1" ?>
2 <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
4     metadata-complete="false" version="3.0">
5
6     <welcome-file-list>
7         <welcome-file>page/index.jsp</welcome-file>
8     </welcome-file-list>
9 </web-app>
  3、/page/index.jsp


html jsp 文件


1 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2     pageEncoding="ISO-8859-1"%>
3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <html>
5 <head>
6 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7 <title>Insert title here</title>
8 </head>
9 <body>
10     <h1>my first jetty web jsp program</h1>
11
12     <h2>Running Jetty web server from our application!!</h2>
13 </body>
14 </html>
  4、servlet启动程序:


java 启动程序


1 package my.project.web.app.jetty;
2
3 import org.eclipse.jetty.server.Server;
4 import org.eclipse.jetty.server.handler.ContextHandlerCollection;
5 import org.eclipse.jetty.webapp.WebAppContext;
6
7 public class AppContextBuilder {
8
9     public static void main(String[] args) throws Exception {
10
11         // 调用jetty服务
12         Server server = new Server(9500);
13         
14         // 加载项目集合
15         ContextHandlerCollection contexts = new ContextHandlerCollection();
16
17         // jsp内容
18         WebAppContext webAppContext = new WebAppContext();
19         webAppContext.setDescriptor(webAppContext + "/WEB-INF/web.xml");
20         webAppContext.setResourceBase(".");
21
22         // 访问路径
23         webAppContext.setContextPath("/");
24
25         // 将 webAppContext项目加载到项目集合中
26         contexts.addHandler(webAppContext);
27
28         // 将项目集合加载到服务器中
29         server.setHandler(contexts);
30
31         // 启动服务器
32         server.start();
33         server.join();
34     }
35 }

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-348087-1-1.html 上篇帖子: 第03篇. 标准Web项目Jetty9内嵌API简单启动 下篇帖子: Maven Debug
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表