Salut,
J'essaie de suivre ce tuto :[ame="http://www.youtube.com/watch?v=Lby37c2tSZY&feature=related"]AJAX Tutorial - using the dwr framework (2/2) - YouTube[/ame].
Mais je n'ai pas de résultats concluant.
J'ai un problème de converter...
Si quelqu'un maîtrise dwr, je suis preneur.
Merci, voici mes fichiers.
web.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>dwrDemo</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <!-- config dwr deb --> <servlet> <display-name>DWR Servlet</display-name> <servlet-name>dwr-invoker</servlet-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> </web-app>
dwr.xml
la classe java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr30.dtd"> <!-- The DWR config file defines what classes DWR can create and remote for use by Javascript. In the example above we are defining 2 classes that are remoted and giving the classes names in Javascript. --> <dwr> <allow> <create creator="new" javascript="Communicator"> <param name="class" value="com.zaneacademy.Communicator" /> </create> <convert converter="bean" match="com.zaneacademy.*"/> </allow> </dwr>
la jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 package com.zaneacademy; public class Communicator { public String doCommunicate(String messageFromBrowser){ System.out.println("message from browser: " + messageFromBrowser); return "In reply to your message \"" + messageFromBrowser + "\": hi from server"; } }
En lib, j'ai ajouté au build path
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!-- lien du tuto : http://www.youtube.com/watch?v=Lby37c2tSZY&feature=related --> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title> dwr Demo </title> <script type='text/javascript' src='dwr/engine.js'></script> <script type='text/javascript' src='dwr/interface/Communicator.js'></script> <script type='text/javascript' src='dwr/util.js'></script> <script type="text/javascript"> function communicateWithServer(){ message-$('messageToBackend').value; Communicator.doCommunicate(message, function(data){ $('messageFromBackend').value-data; }); }; function clearDisplay(){ $('messageToBackend').value-""; $('messageFromBackend').value-""; }; </script> </head> <body> <br/>Communication between Frontend (Javascript Code) and Backend (Java Code): <br/> Message To Backend: <input id='messageToBackend' type="text" style="width: 40%;"> <button id='communicateWithBackend' onclick="communicateWithServer();"> Communicate With Backend</button> <br/>Reply From Backend: <input id='messageFromBackend' type="text" style="background:lightyellow;width: 40%;" readonly="readonly"> <button id='clear' onclick="clearDisplay();"> Clear</button> </body> </html>
dwr.jar
et commons-logging
Partager