1、创建新项目:
步骤:
1)、new project中选择“java Enterprise"
2)、选中系统中安装的jdk路径
3)、选中系统中Tomcat安装路径
4)、项目中勾选Web Application与Struts2
点击下一步,出现如下图所示界面
点击"Finish"完成,出现如下图所示界面:
待会测试时,会出现报错,是由于IDEA提供的jar包不够,缺少几个jar包
2、相关配置:
2.1、web.xml配置
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
改为<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
如下图:
2.2、struts.xml配置如下图:
2.3、添加HelloWorld.jsp,如下图:
2.4、添加jar包;
原因:IDEA中创建的Struts2项目jar包不够,若不添加,将出现如下报错:
[2018-09-15 03:29:17,009] Artifact StructDemo:war exploded: Artifact is being deployed, please wait...
15-Sep-2018 15:29:17.349 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more Filters failed to start. Full details will be found in the appropriate container log file
15-Sep-2018 15:29:17.349 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
[2018-09-15 03:29:17,380] Artifact StructDemo:war exploded: Error during artifact deployment. See server log for details.
15-Sep-2018 15:29:26.833 信息 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [D:\myplace\apache-tomcat-9.0.12\webapps\manager]
15-Sep-2018 15:29:26.880 信息 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\myplace\apache-tomcat-9.0.12\webapps\manager] has finished in [47] ms
添加jar包步骤:
1)下载jar包,下载min版本即可,如下图:
2)添加缺少jar包到项目中
2.1)
2.2)对比发现缺少这三个包:
2.3)点击apply OK 添加后,如下图
2.4)将添加jar包添加到项目中
项目名称右键后点击“Put into Output Root",将在左边WEB-INF的lib目录下看到jar包
点击Apply OK
3、测试运行
点击run ,成功运行
输入localhost:8080/hello
done;