Spring + hibernate + Struts can be integrated in only the third way.

Source: Internet
Author: User

 

1. Use spring's delegatingrequestprocessorReplace the requestprocessor of struts.

1) do not set the automatic loading of applicationcontext in Web. XML, In the struts-config.xml through plug-in settings.

<Plug-in classname = "org. springframework. Web. Struts. contextloaderplugin">
<Set-property value = "/WEB-INF/applicationcontext. XML,/WEB-INF/appcontext. xml" property = "contextconfiglocation"/>
</Plug-in>

2) set the replacement class for requestprocessor in the struts-config.xml.

<Controller processorclass = "org. springframework. Web. Struts. delegatingrequestprocessor"> </controller>

3) do not set the type attribute of action in the <action> element in the struts-config.xml.

<Action Path = "/login" input = "/index. jsp"
Validate = "true" Scope = "request">
<Forward name = "Forward" Path = "/success. jsp"> </forward>
</Action>

4) set the bean forwarded by delegatingrequestprocessor in applicationcontext. xml or other spring bean configuration files. This bean is the action class.

<Bean name = "/login" class = "mypack. loginaction" Singleton = "false">
<Property name = "property1" ref = "otherbean"/>
</Bean>

 

2. Use delegatingactionproxyThis method forwards the request to the action defined in applicationcontext. xml.

1) Same as the first method 1 ).

2) If you try the first method, remove

<Controller processorclass = "org. springframework. Web. Struts. delegatingrequestprocessor"> </controller>

Element.

3) You need to define the type = "org. springframework. Web. Struts. delegatingactionproxy" in the struts-config.xml.

<Action Path = "/login" input = "/index. jsp" Validate = "true"
Scope = "request" type = "org. springframework. Web. Struts. delegatingactionproxy">
<Forward name = "Forward" Path = "/success. jsp"> </forward>
</Action>

4) Same as the first method 4 ).

 

III.Use spring actionsupport.

Spring's actionsupport inherits from org. Apache. Struts. action. Action.

The subclass of actionsupport can be a global variable of the webapplicationcontext type. You can use getwebapplicationcontext () to obtain this variable.

This is the servlet code:

 

Public class loginaction extends Org. springframework. web. struts. actionsupport {public actionforward execute (actionmapping mapping, actionform Form, httpservletrequest request, httpservletresponse response) {loginform = (loginform) form; // obtain the webapplicationcontext object webapplicationcontext CTX = This. getwebapplicationcontext (); logindao Dao = (logindao) CTX. getbean ("logindao"); User u = new user (); U. setname (loginform. getname (); U. setpwd (loginform. getpwd (); If (Dao. checklogin (u) {Return Mapping. findforward ("success");} else {Return Mapping. findforward ("error ");}}}
Configuration in applicationcontext. xml <beans> <bean id = "logindao" class = "com. Cao. Dao. logindao"/> </beans>

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.