Eclipse搭建struts开发环境
2017-05-22 19:01
344 查看
Eclipse搭建struts开发环境
(Eclipse版本:Neon.2 Release (4.6.2)Build id: 20161208-0600struts2版本:2.3.30
Tomcat版本:apache-tomcat-9.0.0.M20
操作系统:ArchLinux
jdk版本:1.8.0_121
)
下载开发所需环境(jdk、tomcat、eclipse、 struts2)
下载jdk1.8.0_121
链接: https://pan.baidu.com/s/1nuMuaPr 密码: 35mz
下载tomcat9.0
链接: https://pan.baidu.com/s/1hrM4oAw 密码: r6sc
下载 struts2.3.30 jar包
链接: https://pan.baidu.com/s/1c2L6AlU 密码: 5bd9
(linux下配置jdk tomcat 详见我博客Linux文章)
新建动态网站工程(Dynamic Web Project)
建完后的项目结构
开始把struts2的必需jar包 复制到 WebContent/WEB-INF/lib 下
(struts2.3.30必需基本包)
(复制完后)
修改web.xml内容
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>Struts2Demo1</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <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> </web-app>
在src目录下新建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> <package name="default" namespace="/" extends="struts-default"> <action name="hello" class="com.action.TestAction"> <result>/success.jsp</result> </action> </package> </struts>
在WebContent目录下新建index.jsp和success.jsp
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"> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <s:a action="hello">Hello</s:a> </ b0f2 body> </html>
success.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"> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <s:property value="hello" /> </body> </html>
新建对应的Action类-TestAction
新建包com.action
新建类TestAction
“`
package com.action;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport {
private String hello;
public String getHello() { return hello; } public void setHello(String hello) { this.hello = hello; } @Override public String execute() throws Exception { // TODO Auto-generated method stub //return super.execute(); hello="Hello,world"; return SUCCESS; }
}
`
完毕
至此项目结构如下
开始调试运行
运行效果
“
相关文章推荐
- 用eclipse搭建struts开发环境
- Eclipse下搭建struts、spring、hibernate开发环境
- Struts+Spring+Hibernate之搭建Eclipse + MyEclipse 开发环境
- struts+spring+hibernate项目开发环境的搭建——eclipse3.3+MyEclipse6.0+MySql4.1
- Eclipse下搭建struts、spring、hibernate开发环境 搭建环境
- Eclipse上搭建Nokia手机的J2ME开发环境
- [原创]Eclipse3.0.1+Lomboz3.0.1+EMF2.0.1+Tomcat 5.0.30 JSP开发环境搭建实战记录
- 用Eclipse3.1 + Myeclipse4.0 + Tomcat5.0 + j2sdk1.5 搭建J2EE开发环境
- eclipse3.02+LomBoz+WebLogic7 搭建JSP开发环境!
- 使用Eclipse+RVDS 2.2搭建 ARM 开发环境
- 用Tomcat插件在Eclipse上搭建可跟踪调试的J2EE WEB开发环境
- 用Eclipse3.2 + Myeclipse5.0GA + Tomcat5.5.17 + j2sdk1.5 搭建J2EE开发环境
- 搭建Eclipse+MyEclipse开发环境
- Eclipse开发J2ME的环境搭建(文章链接收集)
- 搭建Eclipse+MyEclipse开发环境
- 用Eclipse3.2 + Myeclipse5.0GA + Tomcat5.5.17 + j2sdk1.5 搭建J2EE开发环境
- Eclipse3.2中 Java Web 开发环境的搭建之LOMBOZ+TOMCA
- 搭建Windows下基于Eclipse的PHP开发环境
- 用Eclipse3.2 + Myeclipse5.0GA + Tomcat5.5.17 + j2sdk1.5 搭建J2EE开发环境
- 搭建Eclipse+MyEclipse开发环境