Tool version compatibility problem
Struts2 Based on MVC of WEB Frame
Correct
stay Hello Struts In , Will show the most basic Struts Configuration of The follow-up study is carried out on this basis Must read : Framework based programs run successfully , For JAR Package version , The correctness of the configuration file has strict requirements , Anything goes wrong , Will cause the framework program to fail . If you are learning this framework for the first time , Be sure to follow the instructions of the tutorial strictly , Completely imitate the operation , Until you successfully see the running effect . After the first success , Confidence , Ideas will have a better cushion , Then according to their doubts , stay “ success ” Make the desired changes and adjustments to your code , This can greatly save learning time , increase of efficiency , Don't change it at once , Create obstacles to your learning Step 2 : Imitation and troubleshooting Step 3 : stay eclipse Create in Web Dynamic project struts Step 4 : Import jar Bag Step 5 : newly build web.xml Step 6 : to configure struts.xml Step 7 : establish index.jsp Step 8 : Deployed in tomcat In , Restart test Step 9 : Train of thought diagram Step 10 : Runnable project Step 11 : practice
Struts A lot of steps need to be done , Any step is missing , Did something wrong , Can fail , This will affect the confidence of learning , And mistakenly think that this tutorial is impassable .
So first download the runnable project in the upper right corner struts.rar, Unzip and import to eclipse In , Start Tomcat, Observe for normal operation . Make sure you can run , Make sure the tutorial can run , Learn the following . Import to Eclipse For the method of and operation in, please refer to : Import dynamic Web Project to Eclipse In After successful deployment , Test address , You should see the effect shown in the figure http://127.0.0.1:8080/struts/index notes : This is a dynamic project format , I won't support it independent Tomcat Mode deployment
After ensuring that the runnable project can run correctly , Then strictly follow the steps in the tutorial , Imitate the code again .
The imitation process inevitably has code differences , As a result, the expected operation results cannot be obtained , At this moment, by comparison The correct answer ( Runnable project ) And your own code , To locate the problem . In this way , Learning is effective , Troubleshooting is efficient , It can obviously improve the learning speed , Across all the barriers on the way to learning . It is recommended to use diffmerge Software , Compare folders . Put your own project folder , Compare with my runnable project folder . This software is awesome , You can know which two files in the folder are wrong , And clearly marked Here is a green installation and use tutorial : diffmerge Download and use tutorials
stay eclipse New item in struts, use dynamic web project The way . Students who are not familiar with this way , Please refer to
use Dynamic Web Project Develop in a way J2EE application
Download the... In the upper right corner lib.rar, Unzip and copy to WEB-INF/lib in
stay WEB-INF New under directory web.xml
One... Is configured Filter, All requests are filtered to this Filter org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
<web-app> <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> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
<web-app> <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> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
stay
src catalogue Next create a struts.xml File
This is the simplest struts.xml to configure The effect is when visiting index When the path , The server jumps to index.jsp
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="basicstruts" extends="struts-default"> <action name="index"> <result>index.jsp</result> </action> </package> </struts>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="basicstruts" extends="struts-default"> <action name="index"> <result>index.jsp</result> </action> </package> </struts>
stay
web catalogue Create... Under index.jsp,
The content is very simple It's just a sentence Hello Struts2 World
Hello Struts2 World
Hello Struts2 World
Deployed in Tomcat In , Restart tomcat, Then visit the address , Observation effect
http://127.0.0.1:8080/struts/index It is equivalent to realizing servlet of Server jump To index.jsp The function of For deployment methods, please refer to Through Eclipse Start Tomcat-Run On Server
1. All visits will be web.xml Configured in Struts of Filter Intercepted
2. After interception , Just enter struts Workflow of 3. The visit address is /index, According to struts According to struts.xml Configuration in , The server jumps to index.jsp 4. Show index.jsp The content of
In the upper right corner, there is the runnable Project Download corresponding to this knowledge point , I really can't do it myself , Just download and unzip it and compare it
Prepare one hello.jsp File
Through configuration struts.xml Implement the access path /hello Jump to hello.jsp
The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .
![]()
Q & A area
2021-03-24
Access path struts No problem
3 One answer
byxdbyj Jade Jump to the problem location Answer time :2021-07-17
Has the landlord's problem been solved ? I have the same problem ..
Hard training technique Jump to the problem location Answer time :2021-04-08
I solved it , Can be in IDEA In , By creating a new dynamic web project , To solve this problem . Do not import webmaster's project , Instead, create a new . You can refer to this article : https://blog.csdn.net/Awt_FuDongLai/article/details/115523552
Hard training technique Jump to the problem location Answer time :2021-04-08
My situation is to visit http://localhost:8080/struts/index Will report 404 error , visit http://localhost:8080/struts/index.jsp The right page will appear . Does anyone know what's going on
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2021-02-19
For exercises, you cannot access /hello The problem is
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2020-11-29
There is a problem with the filter
2020-04-08
filter Configuration error
2020-02-17
web.xml Jump struts.xml
Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 34 Previous questions , please Click to view
Please... Before asking questions land
The question has been submitted successfully , Auditing . Please
My question Check the question record at , thank you
|