Eclipse配置Struts2.x
问了我同学现在JavaWeb主流框架是哪些。他说基本框架是SSH,struts2+spring+hibernate,流行的是SSM,springmvc+spring+mybatis,原本计划学下Struts1框架呢,这样就不学了,先学下Struts2,首先就是eclipse配置Struts2.
一、下载Struts2
从http://struts.apache.org/download.cgi#struts25101下载struts2的包,这里我选的是min的下载的
二、导入Struts2
下载之后解压,将lib下的所有文件复制到已创建的Struts2项目中。
三、strut2配置
1.在src下创建struts.xml文件,在xml中做如下配置,xml里引入的<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">,这个dtd是用来校验这个xml的内容格式的,如果缺少节点,会跟dtd里的东西对不上,从而报错,这里还要注意一下根节点是<struts></struts>,今天配置的时候就忘记加根结点了。
<?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="default" extends="struts-default"> <default-action-ref name="hello" /> <action name="hello"> <result>/hello.jsp</result> </action> </package> </struts>
2.在WEB-INF/web.xml中配置如下,这里filter和filter-mapping是一一对应的,用各自的filter-name对应,我开始配置的时候定义了两个filter:struts-execute、struts-prepare但只定义了一个filter-mapping:struts-prepare,其实这两个filter的class是可以和到一起的,使用下面的org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter类。
<filter> <filter-name>struts-prepare</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts-prepare</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
3.在WebContext下新建hello.jsp文件,因为在上面的struts.xml中配置的action的result是/hello.jsp。如果hello.jsp放在WEB-INF下,result应该是/WEB-INF/hello.jsp.
<?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="default" extends="struts-default"> <default-action-ref name="hello" /> <action name="hello"> <result>/WEB-INF/hello.jsp</result> </action> </package> </struts>
四、运行
在hello.jsp文件中的body中输入一行<h2>Hello,Strut2!</h2>。重启Tomcat,在浏览器输入http://localhost:8088/MyStruts2/hello。
这里要感谢下我的同学也是我大学室友张蒙,这么晚了还帮忙解决问题。
相关文章
- 测试并发应用(七)配置Eclipse来调试并发代码
- ABP源码分析四十四:ZERO的配置
- eclipse maven plugin 插件 安装 和 配置
- Shark-0.9.0安装配置运行实践
- Env:VIM配置
- java:eclipse安装tomcat插件及配置tomcat
- Linux 配置rdate时间服务器方法
- [转]迄今为止最优的Eclipse运行性能调优 ,含eclipse.ini
- linux(fedora30):安装/配置maven(maven3.6.1)
- apache伪静态配置 .htaccess
- eclipse3.4配置的tomcat server如何部署以前的web项目?
- java+win7+eclipse+Maven+sikuli 配置总结---图形脚本语言
- EntityFramework 系列:实体类配置-根据依赖配置关系和关联
- VRRP配置实例
- Spring Cloud Config配置中心使用(草稿版)
- ASP.NET Core 6框架揭秘实例演示[25]:配置与承载环境的应用
- Groovy的本地安装和Eclipse插件的配置
- Eclipse 下的 Maven的安装及配置
- 配置Tomcat使用https协议(配置SSL协议)
- ubuntu 14.04 hadoop eclipse 0配置基本环境
- eclipse c++ 配置 c++ 17
- ubuntu 下安装eclipse &java环境配置
- Eclipse创建java webproject配置Tomacat和JDK
- Linux环境下Eclipse + Tomcat + MySQL 配置J2EE开发环境的方法
- eclipse中配置tomcat
- eclipse git插件配置
- Eclipse Debug 配置
- Eclipse Debug 配置
- IPv6路由协议实验配置(ospfv3、isis-ipv6、bgp4+)
- java开发,IDE,eclipse联想功能配置,内容提示,候选