IDEA 建立Struts2教程及可能出現的錯誤
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