• 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 }
  • 相关阅读:
    小作业(# 求1-2+3-4+5 ... 99的所有数的和)
    小作业(3、输出 1-100 内的所有奇数 4、输出 1-100 内的所有偶数)
    小作业(求1-100的所有数的和)
    作业小练习(使用while循环输入 1 2 3 4 5 6 8 9 10)
    keepalived介绍
    nginx日志文件配置
    Nginx配置文件编写实例
    Nginx部署流程
    nginx服务介绍
    http协议原理介绍
  • 原文地址:https://www.cnblogs.com/yhql/p/2780156.html
Copyright © 2020-2023  润新知