Recently, an application using spring 1 MVC + hibernate 3 + dwr1 found a strange problem. Where dwr1 is used
When registering a user, determine whether the user exists. The Code is as follows:
DWR Configuration
But when running it, I always said that DWR could not find the userfacade method. I checked all the links again. That's all right. It's the same as the previous program code. I checked it for a lo
See some examples on the internet, for a simple three-level linkage, plus what struts, hibernate, and so on. This Ajax linkage does not know what the relationship with these frameworks, a small demo why the whole so big.
Today, I did an example of dwr+jsp.
Xml:
Copy Code code as follows:
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee
Http://java.sun.com/xml/ns/j2ee/web-app_2_
Believe that many projects, often file upload function bar.
Can I upload a file with Dwr? Simplifies the file upload process.
The answer, of course, is "certainly achievable".
The file upload function with DWR requires more than 3.0 versions.
OK, let's take a look at some basic things about file uploads.
1.html:
2.js
var files = dwr.util.getValue ("file");//This is the method in the Util.j
The previous Web project is already based on the Spring MVC framework and now needs to do a Dynamic Web page refresh feature, using DWR push Technology, server-side updates, immediately displayed on the Web page.
1. Import Dwr.jar Package
2. Configure the Web. xml file, and all the mappings are intercepted by the spring MVC controller and then forwarded by the controllers.
3. Configure the information about DW
Util. js contains some useful function functions for calling on the client page. It can be separated from dwr and independent camp is used in your system.The main functions are as follows:1. Get the page parameter value by $ ()2. addOptions and removeAllOptions3. addRows and removeAllRows Filling Table4. getText: Get the text property value5. getValue: Get the form value6. getValues obtains multiple form values.7. onReturn8. selectRange9. setValue10.
DWR Full Name Direct WEB Remoting principle transforms Java code into JS object for cross-domain accessXml Dwr.xml packageorg.konghao.dwr.model;importjava.io.file;importjava.io.ioexception;import java.io.inputstream;importjava.util.arraylist;importjava.util.list;import javax.servlet.http.httpservletrequest;importorg.apache.commons.io.fileutils;import org.apache.commons.io.filenameutils;importorg.directwebremoting.webcontext;import Org.directwebrem
At the weekend, study dwr at home and do an example. Implements a message from the client to the server, after the message is returned, displayed on the client. The code is as follows:
JSP page:
String path = Request.getcontextpath ();String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%>
Haha, see the address is not AH. The basepath of this page is: Haha, see the address is not AH. The
getdata.jsp
In fact, the use of DWR to get background data is very easy to achieve, but for how to set the browser dynamic refresh Access data is not very clear, according to the information on the Internet to find that the original this is simpler:
function Myshow (){Timer = Window.setinterval ("GetResult ()", 2000);}
As a widely used WEB application development technology, AJAX firmly established its position, followed by some of the common Ajax usage patterns. For example, Ajax is often used to respond to user input and then modify part of the page with new data obtained from the server. However, sometimes the Web application's user interface needs to be updated to respond to asynchronous events that occur on the server side without requiring user action-for example, displaying new messages to an Ajax chat
Generally, the method to obtain the value of the DWR method on the page is
Function Test (){
Dwrtest. Hello (function (data) {alert (data )})
}
It is difficult to return this value for your JavaScript test method. The DWR method returns the value after execution by calling the specified function. We often do this.
Function Test (){
VaR result;
Dwrtest. Hello (function (data) {result = data
This is a web project
The first is the Web. xml file.
Then there is the DWR configuration file DWR. xml located under // WEB-INF //
Then the index. jsp page is used to display the infinite provincial/municipal linkage effect.
City. Java
Package COM. jadyer. model;
Then, the DAO class operated directly with the Oracle database
Package COM. jadyer. dao;
Finally, the database script file
-- Oracle 11g
Spring MVC + DWR verify whether the user name exists. This is the most typical case.
1 In dwr2, note that the configured class name is different from that in dwr1.Changed from UK. Ltd. getahead to org. directwebremoting.New configuration1 2 3 4 5 6 7 8 9 2. You have to change the DTD.
3 DWR. xml
-->
Adopt Dwr+ajax and Struts Development File Upload progress bar
writing a listener and related classes
Do not write yourself, the source code can be from
Http://www.telio.be/blog/2006/01/06/ajax-upload-progress-monitor-for-commons-fileupload-example inside Download,
Download Address
Http://www.telio.be/blog/wp-content/uploads/2006/01/ajax-upload-1.0.war
After downloading, you need to unpack the package at the command line:
Jar XVF Ajax-upload-1.0.w
Two different ways
First, configure directly in the spring configuration file Applictioncontext
Second, separate dwr.xml file configuration
Test class:
Package com.test; public class Test {public string test (string name) {System.out.println ("---------"), return "Hello" + name + "!!!!!"; } }
The first way:
Applicationcontext.xml
DWR Forwarding with Org.directwebremoting.spring.DwrSpringServlet
Xml
Second Kind
Applicationcontext.xml (as with
A JavaScript error occurred while running HelloWorld
"Error: Object does not support this property or method"
In IE browser http://localhost:8000/Struts_Dwr/dwr/test/service can appear SayHelloWorld ();
can also run
The results of the operation are:
SayHelloWorld (); "Hello worldwanxuesi!"
But running with JavaScript in a JSP will report the above error, why.
The JSP code is as follows:
Solution:
To download a dwr.jar on the Internet if 2.0, size 494
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.