搭建struts2+tomcat 开发环境
2013-09-23 10:06
225 查看
1.本着穿一手鞋的原则去struts官网上载struts-2.3.15.1-all
2.环境准备由于我比较赖直接用myeclipse
3.struts-2.3.15.1-all\struts-2.3.15.1\apps\struts2-blank.war 这个是基本的把它解压
(1)struts2-blank\WEB-INF\lib strut2用的jar包 搞定
(2)struts2-blank\WEB-INF\web.xml 复制一下
(3)WEB-INF\classes\example.xml 和 struts.xml 复制到根目录src 复制 jsp java 类
4.myeclipse 新建项目
web.xml
struts.xml
example.xml
HelloWorld.java
ExampleSupport.java
5.部署一下tomcat
访问一下地址:http://localhost:9999/struts2/example/HelloWorld.action 好吧可以了。
2.环境准备由于我比较赖直接用myeclipse
3.struts-2.3.15.1-all\struts-2.3.15.1\apps\struts2-blank.war 这个是基本的把它解压
(1)struts2-blank\WEB-INF\lib strut2用的jar包 搞定
(2)struts2-blank\WEB-INF\web.xml 复制一下
(3)WEB-INF\classes\example.xml 和 struts.xml 复制到根目录src 复制 jsp java 类
4.myeclipse 新建项目
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>Struts Blank</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
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" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results> <result name="error">/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.lang.Exception" result="error"/> </global-exception-mappings> <action name="index"> <result type="redirectAction"> <param name="actionName">HelloWorld</param> <param name="namespace">/example</param> </result> </action> </package> <include file="example.xml"/> <!-- Add packages here --> </struts>
example.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="example" namespace="/example" extends="default"> <action name="HelloWorld" class="example.HelloWorld"> <result>/example/HelloWorld.jsp</result> </action> </package> </struts>
HelloWorld.java
/* * $Id: HelloWorld.java 471756 2006-11-06 15:01:43Z husted $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package example; /** * <code>Set welcome message.</code> */ public class HelloWorld extends ExampleSupport { public String execute() throws Exception { setMessage(getText(MESSAGE)); return SUCCESS; } /** * Provide default valuie for Message property. */ public static final String MESSAGE = "HelloWorld.message"; /** * Field for Message property. */ private String message; /** * Return Message property. * * @return Message property */ public String getMessage() { return message; } /** * Set Message property. * * @param message Text to display on HelloWorld page. */ public void setMessage(String message) { this.message = message; } }
ExampleSupport.java
/* * $Id: ExampleSupport.java 471756 2006-11-06 15:01:43Z husted $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package example; import com.opensymphony.xwork2.ActionSupport; /** * Base Action class for the Tutorial package. */ public class ExampleSupport extends ActionSupport { }
5.部署一下tomcat
访问一下地址:http://localhost:9999/struts2/example/HelloWorld.action 好吧可以了。
相关文章推荐
- 暑期打卡——Ubuntu下的java web开发环境搭建(eclipse+tomcat+mysql+jdk)
- Java Eclipse Tomcat MySql开发javaweb项目环境搭建
- 在服务器搭建javaweb开发环境--安装配置eclips和tomcat
- CentOS6.3+JDK7+Tomcat7.0+MySQL5.5 开发环境的搭建
- Mac OS X上IntelliJ IDEA 13与Tomcat 8的Java Web开发环境搭建
- Eclipse中Java Web 开发环境的搭建--Eclipse+Tomcat+Lomboz
- [Ubuntu下java开发环境搭建]Ubuntu14.04+jdk+myeclipse+tomcat及问题总结
- 用Eclipse、Tomcat、Lomboz搭建jsp开发环境
- struts2.1笔记05:struts2开发环境的搭建
- 使用Maven搭建Struts2+Spring3+Hibernate4的整合开发环境
- 搭建java-eclipse-tomcat 开发环境
- JavaWeb学习心得之开发环境搭建(Tomcat服务器)
- 三种 struts开发环境搭建
- Java开发基础环境搭建(jdk1.7+tomcat7+mysql5.6)
- CentOS7下搭建java开发环境(JDK+Tomcat+MySQL)
- Linux下Java开发环境的搭建Tomcat6+jdk6+eclipse3.5.2+Myeclipse9.0+mysql5.1.47
- 原创:第一节struts1的环境搭建及用户注册案例开发
- linux开发环境搭建---tomcat---jenkis---svn
- Gradle搭建Struts 2.5.14.1基于xml配置文件的开发环境
- Ubuntu下Intellij IDEA 13+Tomcat8开发环境搭建