netty 配置 jsp

这个是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、项目结构如下:

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

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 }

转载于:https://www.cnblogs.com/yhql/archive/2012/11/21/2780156.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值