zoukankan      html  css  js  c++  java
  • maven 配置jetty插件启动 及简单测试

    新建项目jetty-dcs

    选择打包方式为war

    在pom文件里面导入servlet包 和 jetty插件 

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.landau.testjetty</groupId>
      <artifactId>jetty-dcs</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>war</packaging>
      
      <dependencies>
              <dependency>
                  <groupId>javax.servlet</groupId>
                  <artifactId>javax.servlet-api</artifactId>
                  <version>3.1.0</version>
              </dependency>
      </dependencies>
      
      <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>8.1.16.v20140903</version>
                    <configuration>
                        <jvmArgs>-Xms512m -Xmx512m -XX:PermSize=512m</jvmArgs>
                        <scanIntervalSecond>10</scanIntervalSecond>
                        <webApp>
                            <contextPath>/jetty-dcs</contextPath>
                        </webApp>
                        <connectors>
                            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                                <port>8080</port>
                                <maxIdleTime>60000</maxIdleTime>
                            </connector>
                        </connectors>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    </project>

    新建servlet类 重写doGet()

    public class JettyServlet extends HttpServlet {
    
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            System.out.println("=================================");
            req.setAttribute("user", new User(1,"landauNi",23));
            req.getRequestDispatcher("/WEB-INF/hello.jsp").forward(req, resp);
        }
    
    }

    在web.xml里面配置请求拦截

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
        xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <servlet>
            <servlet-name>Hello</servlet-name>
            <servlet-class>com.jetty.test.JettyServlet</servlet-class>
        </servlet>
        
        <servlet-mapping>
            <servlet-name>Hello</servlet-name>
            <url-pattern>/hello</url-pattern>
        </servlet-mapping>
    </web-app>

    书写简单的jsp测试页面

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <%@ page isELIgnored="false" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>hello</title>
    </head>
    <body>
        你好me${user.uName}
    </body>
    </html>

    项目目录结构

    启动方式 jetty:run

    参考:

    http://jingyan.baidu.com/article/d3b74d64f07e101f77e60906.html

    http://blog.csdn.net/guanfl/article/details/65628494#

  • 相关阅读:
    SQLServer数据库自增长标识列的更新修改操作
    “~/Views/Login/Login.aspx”处的视图必须派生自 ViewPage、ViewPage<TModel>、ViewUserControl 或 ViewUserControl<TModel>。
    关于值类型与列类型不匹配,所需类型是 DataRow"的解决方案
    尝试为文件 F:visual studio 2010kbspaperCMSApp_DataProject.mdf 附加自动命名的数据库,但失败。已存在同名的数据库,或指定的文件无法打开或位于 UNC 共享目录中。
    Django快速开发之投票系统
    super() 的入门使用
    [python]模块及包
    [转]大话后端开发的奇淫技巧大集合
    [.net 多线程]ThreadPool的安全机制
    [.net 多线程]Task
  • 原文地址:https://www.cnblogs.com/landauni/p/7181977.html
Copyright © 2011-2022 走看看