同<JETTY嵌入式Web容器的开发(一)>,仍旧采用
jetty-hightide-8.1.4.v20120524.zip
本文采用struts2.1.8和spring 2.5.6
-
ECLIPSE建立一个普通JAVA项目testjetty
建项目步骤同<JETTY嵌入式Web容器的开发(一)>,不做赘述
建成的项目的结构如下:
-
修改/jetty/etc/jetty.xml
同<JETTY嵌入式Web容器的开发(一)>,不做赘述
-
JETTY Service类
Service类同<JETTY嵌入式Web容器的开发(一)> ,不做赘述
-
做一个简单的可执行的服务启动类
package org.jetty.demo; public class JettyServerStart { } |
-
集成入struts和spring
将struts2.1.8和spring 2.5.6的jar包拷贝入项目的buildpath |
Src目录下建立struts.properties和struts.xml\ Src下建立目录/spring,里面建立applicationContext.xml |
项目架构:
-
加入struts,spring的测试逻辑
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> </web-app> |
/spring/applicationContext.xml <?xml version="1.0" encoding="GBK"?> <beans xmlns="http://www.springframework.org/schema/beans" </beans> |
struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC <struts> </struts> |
cn/com/test/action/struts-admin-action.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC <struts> </struts> |
package cn.com.test.action; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.ServletActionContext; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.opensymphony.xwork2.ActionSupport; @Controller("testAction") @Scope("prototype") public class TestAction extends ActionSupport { } |
/webRoot/jsp/success.jsp <%@ page language="java" contentType="text/html; charset=GBK" <!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=GBK"> <title>Insert title here</title> </head> <body> success!!! ${message} </body> </html> |
-
启动服务
执行JettyServerStart |
2012-06-27 17:14:10.859:INFO:oejs.Server:jetty-8.1.4.v20120524 2012-06-27 17:14:11.250:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/testContext,file:/D:/RND/javaathome/eclipsehelio/testjetty/webRoot/} 2012-06-27 17:14:11.250:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/testContext,file:/D:/RND/javaathome/eclipsehelio/testjetty/webRoot/} 2012-06-27 17:14:11.375:INFO:/testContext:Initializing Spring root WebApplicationContext 2012-06-27 17:14:11,375 INFO ContextLoader.initWebApplicationContex 2012-06-27 17:14:11,406 INFO XmlWebApplicationContext 2012-06-27 17:14:11,484 INFO XmlBeanDefinitionReader.loadBeanDefinitions(323)-Loading XML bean definitions from file [D:\RND\javaathome\eclipsehelio\testjetty\bin\spring\applicationContext.xml] 2012-06-27 17:14:11,734 INFO XmlWebApplicationContext 2012-06-27 17:14:11,843 INFO DefaultListableBeanFacto 2012-06-27 17:14:11,843 INFO ContextLoader.initWebApplicationContex 2012-06-27 17:14:11.843:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/testContext,file:/D:/RND/javaathome/eclipsehelio/testjetty/webRoot/} 2012-06-27 17:14:11.843:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/testContext,file:/D:/RND/javaathome/eclipsehelio/testjetty/webRoot/} 2012-06-27 17:14:12,031 INFO XmlConfigurationProvider 2012-06-27 17:14:12,187 INFO XmlConfigurationProvider 2012-06-27 17:14:12,203 INFO XmlConfigurationProvider 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (spring) for class com.opensymphony.xwork2.ObjectFactory 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for class com.opensymphony.xwork2.conversion.impl.XWorkConverter 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.TextProvider 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.ActionProxyFactory 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.conversion.ObjectTypeDeterminer 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface org.apache.struts2.dispatcher.mapper.ActionMapper 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (jakarta) for interface org.apache.struts2.dispatcher.multipart.MultiPartRequest 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for class org.apache.struts2.views.freemarker.FreemarkerManager 2012-06-27 17:14:12,218DEBUG BeanSelectionProvider.debug(57)-Choosing bean (struts) for class org.apache.struts2.views.velocity.VelocityManager to be loaded from the ObjectFactory 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface org.apache.struts2.components.UrlRenderer 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.validator.ActionValidatorManager 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.util.ValueStackFactory 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.util.reflection.ReflectionProvider 2012-06-27 17:14:12,218 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.util.reflection.ReflectionContextFactory 2012-06-27 17:14:12,234 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.util.PatternMatcher 2012-06-27 17:14:12,234 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface org.apache.struts2.dispatcher.StaticContentLoader 2012-06-27 17:14:12,234 INFO BeanSelectionProvider.info(31)-Choosing bean (struts) for interface com.opensymphony.xwork2.UnknownHandlerManager 2012-06-27 17:14:12,234 INFO BeanSelectionProvider.info(31)-Loading global messages from com.demo.struts2.resources.ApplicationResources 2012-06-27 17:14:12,359 INFO StrutsSpringObjectFactor 2012-06-27 17:14:12,375 INFO SpringObjectFactory.info(31)-Setting autowire strategy to name 2012-06-27 17:14:12,375 INFO StrutsSpringObjectFactor 2012-06-27 17:14:13.265:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8088 current thread:30| idle thread:26 |
-
测试
测试访问http://localhost:8088/testContext/test/test.do