English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
studying struts on慕课网2entry-level course, the latest struts downloaded from the official website-2.5.5-all.zip, JDK uses jdk1.6, Tomcat9.0, keep reporting error [java.lang.UnsupportedClassVersionError], version mismatch, but no matter how many versions I changed, none of them worked, and finally I found a relatively new blog post, following his Struts2version has been configured, and it can finally be used.
------However, I still don't understand why struts-2.5.5Whether it is configuring jdk1.6neither jdk1.8neither works well. Those who understand clearly are welcome to give more advice------
1, download Struts2jar package
Download address:http://archive.apache.org/dist/struts/binaries/
I use struts-2.3.14-all.zip this version
2, create a webproject project
The following is a diagram of the project after all files are created.
3, import Struts2required jar package
Because it is just a sample program, only Struts2only the minimum package supported is enough, there are various opinions on adding the minimum package on the Internet, here is a safe method.
unzip the compressed package struts-2.3.14-all.zip, there is a struts2-blank.war package, open it, go to WEB-INF/directory below, as shown in the figure, is the minimum package required. The packages included should be related to the specific Struts version.
(because the latest version of struts used before)-2.5.5-all.zip, without struts2-blank.war package, this is also one of the reasons to give up the latest version of struts2(one of the reasons for this)
4, configure web.xml
Next, we enter the specific configuration coding stage.
It is important to note that:
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
different versions, the filter class will be different, modify it according to your struts version
5, configure struts.xml
Next, we need to create the struts.xml file and configure struts2the action to be called. Create it directly under the src directory, so it will be automatically deployed to WEB when deployed-INF/directory below, or directly create it in WEB-INF/directory below.
Among them, the package element, similar to the mechanism of Java package, is a tool used for classification, the extends attribute, as the name suggests, inherits struts-default package provides all the information of this package, generally it is best to inherit it when we create a package ourselves, because it provides most of the functions for us, you can use struts2-core jar package of struts-Find this package in the default.xml file. The action element corresponds to your form, for example, if your form's action="helloworld", then the form submitted will pass the parameters to the implementation class of action's name="helloworld". The result element is the result of the action, which is selected by the control field returned by the action class.
6, Write action class (HelloWorldAction.java)
This class is mainly used for struts2Jump to this action after that. The default execution of execute() method and return characters according to the result. Then struts.xml jumps to the corresponding page according to the returned characters
7, Write jsp page
Create a new jsp page to display information. result.jsp
8, Deployment and Running
Run this project in Tomcat.
Then open the browser and enter http://localhost:8080/HelloWorldStruts2/helloworld will get the corresponding page result of result.jsp
referance:
struts2flow and a series of related knowledge code analysis
struts2Introduction and Code Examples
Summary
That is all about struts in this article2All the detailed content of getting started (setting up the environment, configuration, examples), hoping it will be helpful to everyone. Interested friends can continue to read other related topics on this site, and welcome to leave a message if there are any shortcomings. Thank you for your support to this site!
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email for reporting. Provide relevant evidence, and once verified, this site will immediately delete the infringing content.)