打开idea file->new project->JAVEE->WebApplication勾选 struts2(idea 2018默认struts2.5) 没有自己下的lib的话,就直接让它自己download,或者自己选择自己下载的Struts2的lib
![[2019 struts2学习]使用idea搭建环境_struts](https://file.cfanz.cn/uploads/png/2023/10/27/18/bbK6OI86E9.png)
重点说一下,这里有个小坑,如果是选择idea 默认的话,首先lib包中,会缺
![[2019 struts2学习]使用idea搭建环境_xml_02](https://file.cfanz.cn/uploads/png/2023/10/27/18/01a2db441a.png)
java.....GA这个jar包,去Struts2官方网站下载Struts2的相关jar,从lib 目录中,弄出来加进去就行.
然后,默认会生成web.xml,structs.xml等需要的文件,但是web.xml中生成的Struts2的过滤器的filterclass是不对的,需要将core中
![[2019 struts2学习]使用idea搭建环境_struts_03](https://file.cfanz.cn/uploads/png/2023/10/27/18/73NKY4J404.png)
的
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter修改到web.xml中filter-class的位置,然后
在src下创建com.域名.action,创建自己的action,例如
![[2019 struts2学习]使用idea搭建环境_ide_04](https://file.cfanz.cn/uploads/png/2023/10/27/18/211fb5BVa4.png)
action类中默认的规则,方法是public修饰,返回值为String类型,默认方法名execute.
然后在structs.xml中配置映射关系,
![[2019 struts2学习]使用idea搭建环境_struts_05](https://file.cfanz.cn/uploads/png/2023/10/27/18/d1ScVMcOVa.png)
需要创建对应的jsp
[声明,本人之前学的SSM,因为最近公司给的老项目有Struts2,所以临时学,有什么不对的地方,请大家指正!]
