Jquery & DWR & SSH2

Source: Internet
Author: User

Today, after unremitting efforts, I finally gotSSH2 + DWR + jqueryThe example is not easy. After all, I have never touched this form of things before. I want to take a good note.

FirstSSH2That isSpring + struts2 + hibernate. This is currently popularJava WebApplication Development Mode. The key to this simplicity is to ensure that the class libraries of your applications do not conflict with each other. Otherwise, you will be exhausted simply by looking for errors, because these three frameworks use many third parties.JarPackages, theseJarPackages in different versions may conflict with each other. So first, let's take the environment andJarPackage list.

Environment:Spring2.5.6 + struts2.1.8 + hibernate3.5.2

JarPackage list:

  • Antlr-2.7.6.jar;
  • Aspectjrt. Jar
  • Aspectweaver. Jar
  • C3p0-0.9.1.2.jar ---This isC3p0Data SourceJarPackage, you can chooseDBCPBut I do not recommend it.
  • Cglib-nodep-2.1_3.jar
  • Common-annotations.jar
  • Commons-collections-3.1.jar
  • Commons-fileupload-1.2.1.jar
  • Commons-logging.jar
  • Dom4j-1.6.1.jar
  • Dwr-1.1.1.jar --- DWRDriver package
  • Freemarker-2.3.15.jar
  • Hibernate3.jar
  • Javassist-3.9.0.GA.jar
  • Jta-1.1.jar
  • Log4j-1.2.15.jar
  • Ognl-2.7.3.jar
  • Ojdbc5.jar ---This isOracleOfJDBCDriver package
  • Slf4j-api-1.5.8.jar
  • Slf4j-log4j12-1.5.0.jar
  • Spring. Jar
  • Spring-aop.jar
  • Spring-beans.jar
  • Spring-context.jar
  • Spring-context-support.jar
  • Spring-core.jar
  • Spring-jdbc.jar
  • Spring-orm.jar
  • Spring-tx.jar
  • Spring-web.jar
  • Struts2-core-2.1.8.1.jar
  • Struts2-spring-plugin-2.1.8.1.jar
  • Xwork-core-2.1.6.jar

The boys put these Jar Packages can be integrated directly. SSH2 Now, you can simply use your heels and do not need to perform steps as you have on the Internet. As for the configuration file, I should not write it. There are two in total, one is Spring Configuration File Applicationcontext. xml , Mainly configure the data source, Sessionfactory , Transactionmanager . Then configure how to manage Bean If you like <Bean> Node configuration, you can write the configuration file. If you like to use annotation configuration, open the component scan. <Context: component-scan> For Transactionmanager The same is true for the configuration. If you like the configuration file or annotation, enable the annotation driver. <TX: annotation: driven> It's easy. The second one is Struts. xml , Since Spring Integration, then Action Of course, it should be handed over Spring Therefore, a constant must be configured 【 Struts. objectfactory ]. For other configurations Package And Action Use your heels. As Hibernate Are you still using the ing file?

 

The following is the focus, that is, how to use it in your system at the same time.JqueryAndDWR. To be honest, so far I have not understood what the two guys are focusing on. What are the differences between them? What are the application scenarios? I have to learn more. However, from the information on the Internet, the former focuses more on the interface and has a big vote control, and the latter seems to focus more on interaction with the background. I can only say that I am not sure, maybe not. Don't be misled by me.

 

First DWR Introduced to the application. I have already discussed this. I can refer to another article. Blog . However, it must be noted that the entire application is based on Spring Framework management Bean , So DWR You cannot create it yourself. JavaBean That is DWR From Spring Container entry acquisition Bean . To achieve this goal DWR. xml In the configuration file, we should:

<Create creator = "Spring" javascript = "servicebean">

<Param name = "beanname" value = "servicebean">

</Create>

In general, we usually configure it:

<Create creator = "new" javascript = "servicebean">

<Param name = "class" value = "XXX. yyy. Zzz. servicebean">

</Create>

Do you see the difference? In the first configurationValuePay special attention to the attribute value. This value must be passed throughSpringOfGetbean (stringParameter Value)MethodBeanThe value of the string parameter, otherwise it will not work.

 

Second, modifyWeb. xmlSetDWROfServletParameters are not described in detail.

 

Step 3:WebrootCreate a directory to storeJSFile andCSSFile, I guess it cannot be placedWEB-INF. OtherwiseJSPFile cannot be referenced directly.

 

Step 4: Jquery Of JS File Down If you need Jquery Of UI In addition Jquery Core JS In addition Jquery-ui.min.js And Jquery-ui.css Because the former requires CSS File to run.

 

Step 5:JSPIn the fileDWRWillEngine. jsAndUtil. jsIf you need to callJavaBeanFor exampleServicebean, You need to add it.SRCFor more information about attributes, see the previous article.Blog.

 

Step 6:JqueryOfJSAdd, writeDWROfJSLater, it must be later. At least this is the case for me. I dropped them all and found thatDwrutilAn error is reported.

 

Step 7, becauseJqueryAndDWROfUitlConflict, so when writingScriptUse this method to prevent conflicts:

VaR J = jquery. noconflict ();

ThenJqueryAll 【$] SymbolJ.

 

So far, integration is complete, of courseCSSFile Import is also required, and I will not write it. Remember, because these files are introducedJSPSo you must add$ {Pagecontext. Request. contextpath}Otherwise, no. Also, if you find thatCSSNo effect. Check theseCSSWhether the file passesURLSome external resources, such as images, can be referenced.

My page is as follows:

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.