Struts2.5+eclipse+tomcat8.5配置
2017-05-13 23:08
351 查看
1. 下载struts2.5文件并解压
2. 进入struts-2.5.10.1-all\lib
3.找到下图中的jar包导入到eclipse的web工程下的WIn-INF下的lib文件夹中
4. 配置web.xml
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>框架测试</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> <!-- struts配置 --> <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><!-- 对-ura用 --> </filtermpping> </web-app>
5.action类
package test; public class HelloStruts{ public String execute() { System.out.println("执行action"); return "success"; } }
6. 配置struts.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <package name="test" namespace="" extends="struts-default"> <!-- 包名自定 --> <action name="hellostruts" class="test.HelloStruts" method="execute"> <!-- name: action名称,在jsp页面用 action的name.action访问 --> <!-- class: 实现类 --> <!-- method: 实现的方法 --> <result name="success"><!-- 结果集 ,根据name的值转到不同的页面 --> /test.jsp </result> </action> </package> </struts>
7. 测试页面index.jsp和test.jsp
index.jsp:<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!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>Insert title here</title> </head> <body> <s:form action="/hellostruts.action"><!--/actionname . action--!> <s:submit value="Click Here"></s:submit> </s:form> </body> </html>
test.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>Insert title here</title> </head> <body> <h1>Hello Action!</h1> </body> </html>
web工程目录结构:
相关文章推荐
- eclipse配置tomcat8.5
- Tomcat8.5版本在eclipse中的配置
- eclipse配置tomcat8.5
- eclipse配置tomcat8.5(注意是8.5)
- 如何配置eclipse+struts+lomboz+tomcat
- Mac下 Eclipse 配置struts-2.5
- Struts2.5在Eclipse的配置问题
- eclipse配置Struts2至Tomcat8.5 全过程搭建
- Struts 2.1在windows 7中的配置(Tomcat 6+JDK 6以及Eclipse )图文
- eclipse配置tomcat8.5报错The Apache Tomcat installation at this directory is version 8.5.4. A Tomcat 8.0
- Eclipse3.1 + struts + tomcat + lomboz安装配置过程
- (eclipse版)Struts环境配置手册
- 整合Windows 2000 + j2sdk(还要安装NetBeans或 eclipse及其配置) + apache2 + php-4.3.10 + mysql + Tomcat 4 + jk2(整合APACHE和TOMCAT)
- Struts环境配置手顺(eclipse版),包括SQL Server的连接
- [转]eclipse+tomcat+lomboz的安装配置说明
- Eclipse3.0.1+Myeclipse3.8.2+tomcat5开发第一个struts应用(配置篇
- 配置Eclipse3.0开发JSP的环境(Tomcat版)
- eclipse+tomcat环境配置
- [转]eclipse+tomcat+lomboz的安装配置说明
- eclipse+tomcat+lomboz的安装配置说明