The following is a description of configuring Struts2 in Eclipse
Download Struts2 's Zip package
I downloaded the 2.3.32 version
After decompression
Apps directory: Examples of Struts2
Docs directory: Documents for STRUTS2
LIB Directory: Class library for Struts2
SRC Directory: Some resources about STRUTS2
There are a few examples below the Apps directory
Extracting with Jar
JAR-XVF Struts2-blank.war
After decompression to get
Find the Struts.xml file under Struts-2.3.32\apps\web-inf\classes
Configuring the Tomcat server inside eclipse
The TOMCAT9 package is downloaded on my machine, so the configuration Tomcat9
Then choose the location of your tomcat.
After the configuration is done
Create a Web project in eclipse
This is when it's done.
Copy the Struts.xml file to the SRC directory of the Eclipse new project, in my project such as:
Open the Lib directory under the Web-inf directory that you extracted the struts2-blank.war from, such as:
Copy all the jar packages to the WebContent web-inf Lib directory of the new project Struts2learn, in my project such as:
There is a Web. xml file in the Web-inf directory of the extracted Struts2-blank.war
The contents of the file are as follows:
<?XML version= "1.0" encoding= "UTF-8"?><Web-appID= "Webapp_9"version= "2.4"xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <Display-name>Struts Blank</Display-name> <Filter> <Filter-name>Struts2</Filter-name> <Filter-class>Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</Filter-class> </Filter> <filter-mapping> <Filter-name>Struts2</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping> <welcome-file-list> <Welcome-file>Index.html</Welcome-file> </welcome-file-list> <!--restricts access to pure JSP files-access available only via Struts action - <Security-constraint> <Display-name>No Direct JSP Access</Display-name> <web-resource-collection> <Web-resource-name>no-jsp</Web-resource-name> <Url-pattern>*.jsp</Url-pattern> </web-resource-collection> <Auth-constraint> <Role-name>No-users</Role-name> </Auth-constraint> </Security-constraint> <Security-role> <Description>Don ' t assign users to this role</Description> <Role-name>No-users</Role-name> </Security-role></Web-app>
Will <filter></filter> and <filter-mapping></filter-mapping> element into the Web. xml file of Eclipse new project Struts2learn, my web. xml file looks like this:
Open the copied struts.xml file in Eclipse, comment out the contents of <struts> and </struts> in the file, and add the code as follows:
< Packagename= "Default"namespace="/"extends= "Struts-default"> <Actionname= "Hello"> <result>/hello.jsp</result> </Action></ Package>
To create a new hello.jsp file in Ecplise, write the following code between the <body> tags:
At this point, the development environment was initially completed.
Configure Struts2 in Eclipse