A summary of learning STRUTS2 Experience

Source: Internet
Author: User

One, struts access path problem

1) Struts2 thought: Revolve around "action", as long as you find "action" it will know what to do.

First configure Struts.xml, we can see that the action name= "index", and result needs to return to an interface "index.jsp"

<struts>

<package name= "Default" namespace= "/" extends= "Struts-default" >
<action name= "Index" >

<result >

/index.jsp
</result>
</action>
</package>

</struts>

2) Modify "index.jsp", output only one sentence: Hello struts2!

<title> Home </title>

<body>
Hello struts2!
</body>

3) Deploy the project, restart tomcat7.0 in the Address bar to enter Http://localhost:8080/Struts1/index (or http://localhost:8080/Struts1/index.action)-- > enter, the result is as follows:

4) When we change the "name" of the "action", the other place is unchanged, corresponding to the address bar also changed its name, but there will be no previous results, error (Cannot find "action").

<struts>

<package name= "Default" namespace= "/" extends= "Struts-default" >
<action name= "Hello" >
<result >
/index.jsp
</result>
</action>
</package>

</struts>

Results:

5) Workaround: From the above, this situation requires restarting the service and redeploying the project. Now there is a way to do this once and for all: Add constants to the Struts.xml file <constant name= "Struts.devmode" value= "true"/> so that it has been in development mode (IE development modes) ( It is important to note that the default value of value "false" is changed to "true" in order to be a development mode). Then you need to restart the service, run again, and succeed.

In order to verify that the method is valid, you can change the "action" name to the previous "index", but do not restart the service, run directly, practice proves: This method is feasible.

6) Tips Summary i:1 can be used when writing programs: The Address bar needs to enter the corresponding project name, but too long easy to write wrong, it's okay

Simply click on the item and right--->copy qualified name to fill in the address bar with the correct project name.

2. When you want to see the source code of the Struts jar package, click the directory directly: Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter, you will only see this interface

Don't worry, you can do the following: Right--->properties-->java the Source attachment-->external folder (external directory) on the Struts2-core-2.2.1.jar file-- >ok. It is important to note that the path cannot be wrong.

Similarly, to see its doc document, right-click on the Struts2-core-2.2.1.jar file-->properties-->javadoc location-->browse-->ok--> new class --paste a sentence in Web. xml: Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter f;--> Press F1 to see the right Doc document in the "Help" directory.

A summary of learning STRUTS2 Experience

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.