In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to integrate SSH-DWR and other technologies", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to integrate SSH-DWR and other technologies" this article.
Ssh consolidation steps:
Step 1: add support
1: create tables, configure database connections (switch to database view or hibernate view)
2: add hibernate, spring and struts support in sequence (switch to j2ee view and build web project
Add hibernate, spring, struts (myeclipse menu-- > add project-- > hibernate, spring, struts)
Note: hibernate does not need to create sessionfactory when integrating spring, that is to say, not when adding hibernate support
You need to check the box that created the sessionfactory.
3: generate pojo classes, create a dao package to put the DAO classes together (switch to database view or hibernate view and find the table in the corresponding database right-click: Hibernate Reverse
Engineering)
Option description: Java src folder selects the project under the src directory under the multi-box and the first three are checked.
The mapping file configuration for the pojo class. Be aware of the table cascading problem, which may cause some operations to fail if not properly configured (when operating on the master table, the slave table also operates at the same time.): set the cascade property in the set after the mapping file. Such as:
Cascade = save-update (cascading add) add both master table and n slave tables, cascade = all are all cascaded
4: if DWR is involved, then you have to copy the DWR development package under lib, and copy dwr.xml and dwr20.dtd (prompt file) to WEB-INF
Under the directory (as for how to configure, we will post it in detail below)
Step 2: backend business, .xml file configuration (if it is developed with MyEclipse6.5, a gold dictionary exception may occur. The solution is to select the project-> Build Path- > Configure.
-> Remove asm-2.2.3.jar development package in Libraries, and then delet under lib)
1: start to write the business layer and extract interface classes. Write the dao layer. Because the business layer invokes the dao layer, you can write the business first, even if you finish the second.
The step is half done.
2: you can choose to configure the web.xml file.
1) specify the path configuration for the applicationContext.xml files supported by spring (under WEB-INF by default)
Code:
ContextConfigLocationparam-name > classpath:app*.xmlparam-value > context-param >
2) to avoid shutting down session before the transaction is completed, we can set the OpenSessionInViewFilter filter. This is
It involves the problem of lazy loading. In fact, there are several common ways to avoid. For example: set in the primary key mapping file of the pojo class
Add a property to lazy= "false" (load the associated table immediately, default to true). Another option is to use code control to load the key immediately.
The word fetch. For example, join fetch from An a join fetch a.
(mapping can be all files) openssionfilter-name > org.springframework.orm.hibernate3.support.OpenSessionInViewFilterfilter-class > filter >
3) filter to solve the coding problem (mapping can be all files)
Encodingfilter-name > org.springframework.web.filter.CharacterEncodingFilterfilter-class > filter >
4) listeners loaded by the configuration file (no mapping)
Org.springframework.web.context.ContextLoaderListenerlistener-class > listener >
5) if equipped with DWR, you must register for it.
Dwrservlet-name > org.directwebremoting.servlet.DwrServletservlet-class > debugparam-name > trueparam-value > init-param > servlet > dwrservlet-name > / dwr/*url-pattern > servlet-mapping >
Note: if you integrate ssh3, you may report an error during DWR testing because ssh3's core filter will intercept it, resulting in
An error was reported during the test. We will give a specific solution in the next ssh3 integration process analysis.
(the mapping file above can be all files)
3: now you can create action classes, and configurations. Control
If struts support is added, the core controller ActionServlet will be automatically registered in web.xml
The workflow of the core controller is involved here. The execute method is overridden in action. To put it simply, when the client sends a HTTP request, it will be intercepted by the core controller.
The core controller requests to populate ActionForm. Then go to Action. In Action, all we have to do is populate the information in form into the
Our own ActionForm is fine, such as: Department table Form type department Form (populate the information in form into the form) = (department table Form) form
Here are a few points to pay attention to:
1) Registration page: note that action ends with .do
2) write classes, inherit ActionForm (FormBean), interface properties, and generate set/get methods
(types can be: 8 basic data type-level wrapper classes and their arrays. You can also String,java.sql.Date and its array)
3) write the class, inherit the Action, rewrite the execute method, and call the business. You can handle a business with an action class, or you can do it in a
There are several places where multiple businesses are handled in the action class. You can add a parameter p = "xx" after the page action .do
Add the attribute parameter= "p" in struts-config.xml- > action-mapping- > action directly in the requested action class
Get the value of the parameter p and call the corresponding method.
4) create a struts-config.xml file in WEB-INF and register actionForm,action
And determine the relationship among interface / actionForm/Action.
Action specific configuration file struts-config.xml:
Code:
1. Configure actionForm
Form > form-beans >
two。 Configure action
Action > action-mappings >
Description: emp.do of action in / emp jsp page? Proxy class: type= "org.springframework.web
.struts.DelegatingActionProxy "
4: configure applicationContext.xml for spring
The main features of spring support are IOC (inversion of control, dependency injection) and AOP (aspect-oriented programming).
The degree of coupling between layers. It's about the relationship. The only thing to do is to change the file leader.
1) change the file leader
2) the dao layer bean has been generated automatically, so you need to create a bean.
Such as: property > property > bean > such as: property > bean > property > bean >
Description: sessionFactory is automatically generated by the following bean id.
Property > bean > tx:attributes > tx:advice > aop:config >
Description: com.service.*.* (..) Under the com package. Service business layer package. All classes. All methods (.)
5: now it's time to configure DWR for the configuration file dwr.xml.
1) set
File opening is configured as follows:
"- / / GetAhead Limited//DTD Direct Web Remoting 2.0//EN"dwr20.dtd" >
Explanation: cut off the previous paragraph "http:...dwr20.dtd" in "dwr20.dtd" and the rest is "dwr20.dtd" and ok.
2)
Convert > param > create > allow > dwr >
Description: need to import dwr.dtd file for prompt, remember to say no, of course.
Com.pojos.* all pojo classes, converter= "bean" is fixed, bean can also be converted into hibernate
Javascript= "myjs" is custom, creator= "spring" is fixed, param name= "beanName" is fixed
Yes, tsaleformService in value= "tsaleformService" is in applicationContext.xml.
The id of the corresponding business layer bean below is like the id above.
Step 3: it's about how to do DWR testing now. In the browser, under the project name directly / dwr .dwr is just in web.xml
The mapping name configured in is as follows: dwr.
If the test succeeds, your custom "myjs" link will appear. After entering, you can test the business layer transaction.
This summary is my summary in a morning is not very professional, very comprehensive, I am also with the mood of review while turning on the computer to the source code thinking step by step, word by word!
The above is all the content of this article "how to integrate SSH-DWR and other technologies". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.