1、先到官网下载struts2-2.5的min包
2、新建项目,点击struts2的包,我们使用的是我们上面下载的包
3、这个时候来到web.xml,由于我们用的是struts2–2.5,所以这里要把红色的ng去掉,去掉之后就不显示红色了。
4、总所周知,建立完后会有一堆依赖问题要解决,进入project Structure
5、选中problems,进行修复
6、struts部分已经配置好了,现在把tomcat配置一下就行了
7、进入tomcat的deployment中,添加artifact
8、配置完毕,写个action测试一哈
Code:LoginAction.class
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
@Override
public String execute() throws Exception {
System.out.println("success...");
return SUCCESS;
}
}
Code: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="demo" extends="struts-default" namespace="/">
<action name="test" class="LoginAction" method="execute">
<result name="success" >/index.jsp</result>
</action>
</package>
</struts>
9、结果: 配置成功!
另外这里记一个错误,是由struts2环境不当引起的,根据上面的教程,创建的项目就不会有这个问题
报错为:
[2018-12-09 04:32:04,033] Artifact TestSSH:war exploded: Artifact is being deployed, please wait…
09-Dec-2018 16:32:04.197 警告 [RMI TCP Connection(3)-127.0.0.1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
09-Dec-2018 16:32:04.292 严重 [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
09-Dec-2018 16:32:04.292 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [/ssh] startup failed due to previous errors
[2018-12-09 04:32:04,307] Artifact TestSSH:war exploded: Error during artifact deployment. See server log for details.
通过这篇博客学习:https://blog.csdn.net/skullFang/article/details/78202338?utm_source=blogxgwz8