Jetty+Struts+Spring Demo

1、开发环境
windows7、MyEclipse8.6、jetty9.2

目录结构

jettyWeb
    src
        com.jasper.test
            action
                HelloWorld.java
        applicationContext.xml
        struts.xml
    jetty
        start
            Start.java
    lib
        javax.el-3.0.0.jar
        javax.servlet.jsp-2.3.2.jar
        javax.servlet.jsp-api-2.3.1.jar
        jetty-http-9.2.17.v20160517.jar
        jetty-io-9.2.17.v20160517.jar
        jetty-jsp-9.2.17.v20160517.jar
        jetty-jsp-jdt-2.3.3.jar
        jetty-security-9.2.17.v20160517.jar
        jetty-server-9.2.17.v20160517.jar
        jetty-servlet-9.2.17.v20160517.jar
        jetty-util-9.2.17.v20160517.jar
        jetty-webapp-9.2.17.v20160517.jar
        jetty-xml-9.2.17.v20160517.jar
        servlet-api-3.1.jar
    slib
       asm-3.3.jar
       asm-commons-3.3.jar
       asm-tree-3.3.jar
       commons-fileupload-1.3.2.jar
       commons-io-2.4.jar
       commons-lang3-3.4.jar
       freemarker-2.3.23.jar
       javassist-3.11.0.GA.jar
       log4j-api-2.5.jar
       ognl-3.1.10.jar
       struts2-core-2.5.2.jar
       struts2-spring-plugin-2.5.2.jar
    splib
       aopalliance-1.0.jar
       commons-logging-1.1.3.jar
       spring-aop-4.3.2.RELEASE.jar
       spring-beans-4.3.2.RELEASE.jar
       spring-context-4.3.2.RELEASE.jar
       spring-context-support-4.3.2.RELEASE.jar
       spring-core-4.3.2.RELEASE.jar
       spring-expression-4.3.2.RELEASE.jar
       spring-tx-4.3.2.RELEASE.jar
       spring-web-4.3.2.RELEASE.jar

    WebRoot
        WEB-INF
            web.xml
        index.jsp



web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>jettyWeb</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Spring配置 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- 指定Spring Bean的配置文件所在目录。默认配置在WEB-INF目录下 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
<!--        <param-value>WEB-INF/applicationContext.xml</param-value>-->
        <param-value>classpath:/applicationContext.xml</param-value>
    </context-param>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>



applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <bean id="hello" class="com.jasper.test.action.HelloWorld" />
</beans>



struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />

    <!-- struts和spring整合,设置spring来管理Action Bean -->
    <constant name="struts.objectFactory" value="spring"/>

    <package name="default" namespace="/" extends="struts-default">
        <action name="helloWorld" class="hello" method="hello">
            <result name="success">/index.jsp</result>
        </action>
    </package>
</struts>


Start.java

package start;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class Start {
    public static void main( String[] args ) {
        Server server = new Server(8082);

        WebAppContext context = new WebAppContext();
        context.setContextPath("/jettyWeb");
        context.setDescriptor("WebRoot/WEB-INF/web.xml");
        context.setResourceBase("WebRoot");
        context.setParentLoaderPriority(true);

        server.setHandler(context);

        try{
            server.join();
            server.start();
        } catch (InterruptedException e) {
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}



HelloWorld.java

package com.jasper.test.action;

public class HelloWorld {
    public String hello(){
        System.out.println("hello World !");
        return "success";
    }
}



index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!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=UTF-8" />
        <title>sssss</title>
    </head>
    <body>
        hello jetty !
    </body>
</html>
阅读更多
上一篇Jetty+Struts Demo
下一篇SQLite嵌入式数据库
想对作者说点什么? 我来说一句

demo demo demo

2011年05月31日 2.36MB 下载

百度地图demo

2018年04月24日 143.2MB 下载

java发送邮件Demo

2018年04月17日 7.23MB 下载

环信 demo

2018年01月05日 76.93MB 下载

Test Demo Demo

2018年02月04日 225.05MB 下载

Demo Jdeveloper

2011年09月25日 8.05MB 下载

socket上传经纬度

2018年07月06日 3.69MB 下载

切水果源码

2017年09月12日 3.72MB 下载

cesium demo

2018年05月18日 8.85MB 下载

没有更多推荐了,返回首页

关闭
关闭