Dwr Implements user management demo and dwr user management demo

Source: Internet
Author: User

Dwr Implements user management demo and dwr user management demo

DWR:

Direct Web Remoting is an open-source Remote Server Ajax framework used to improve the interaction between web pages and Java. It can help developers develop websites that contain AJAX technology. It allows the code in the browser to use JAVA functions running on the WEB server, just as it is in the browser.

Demo:

Pom. xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>com.demo</groupId>  <artifactId>user-manage</artifactId>  <version>0.0.1-SNAPSHOT</version>  <packaging>war</packaging>  <dependencies><dependency><groupId>org.directwebremoting</groupId><artifactId>dwr</artifactId><version>3.0.M1</version></dependency><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version></dependency></dependencies><build><plugins><plugin><groupId>org.mortbay.jetty</groupId><artifactId>jetty-maven-plugin</artifactId><configuration><scanIntervalSeconds>200</scanIntervalSeconds><webApp><contextPath>/user</contextPath></webApp><connectors><connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"><port>9080</port><maxIdleTime>60000</maxIdleTime></connector></connectors></configuration> <executions>                      <execution>                          <phase>package</phase>                          <goals>                              <goal>run</goal>                          </goals>                      </execution>                  </executions>  </plugin></plugins></build></project>


Web. xml:

<?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_2_5.xsd"id="WebApp_ID" version="2.5"><display-name>DWR (Direct Web Remoting)</display-name><description>A Simple Demo DWR</description><listener><listener-class>org.directwebremoting.servlet.EfficientShutdownServletContextAttributeListener</listener-class></listener><listener><listener-class>org.directwebremoting.servlet.EfficientShutdownServletContextListener</listener-class></listener><!-- <listener> <listener-class>org.directwebremoting.servlet.DwrListener</listener-class> </listener> --><servlet><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><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>dwr-invoker</servlet-name><url-pattern>/dwr/*</url-pattern></servlet-mapping></web-app>

Dwr. xml

<? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE dwr PUBLIC "-// GetAhead Limited // DTD Direct Web Remoting 3.0 //" http://getahead.org/dwr/dwr30.dtd "> <dwr> <allow> <create creator =" new "> <param name = "class" value = "com. demo. service. userService "/> </create> <! -- Configure the converter --> <convert converter = "bean" match = "com. demo. model. User"/> </allow> </dwr>

UserService:

package com.demo.service;import java.util.ArrayList;import java.util.List;import com.demo.model.User;public class UserService {public static final String SUCCESS="success";public String add(User user){System.out.println(user);return SUCCESS;}public String deleted(int userId){System.out.println("userId:"+userId);return SUCCESS;}public String update(User user){System.out.println("update:"+user);return SUCCESS;}public List<User> list(){List<User> users=new ArrayList<User>();users.add(new User(1,"aa"));users.add(new User(2,"bb"));users.add(new User(3,"cc"));return users;}}

List. jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>    <%        %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
Test:

http://localhost:9080/user/list.jsp





Who has the demo of dwr reverse push''

We recommend that you refer to the official Demo for more information:
Directwebremoting.org/dwr-demo/

Three demos are introduced in total:

1. Server-Side Clock: A clock that is updated by the server using Reverse Ajax. Demonstrates access from a non-http thread.

2. Table Update A table that is updated by the server using Reverse Ajax. Demonstrates how to filter a page so that only certain users receive updates (based on an attribute in the ScriptSession ).
3. Chat examples, one with the logic in JavaScript, and the other with logic in Java

How does dwr implement the singleton mode?

For the creation of Singleton classes, it is best to use BeanShell and BSF to instantiate objects.

Scripted: creates an object through BSF using a scripting language, such as BeanShell or Groovy.
To use this generator, you need to put some auxiliary libraries under the WEB-INF/lib Folder: for example, BSF jar package, you need to use the script language jar package. The new generator has been declared by default in DWR: <creator id = "script" class = "uk. ltd. getahead. dwr. create. scriptedCreator "/> This creator uses BSF to execute the script to obtain the Bean, for example: <allow>... <create creator = "script" javascript = "EmailValidator"> <param name = "language" value = "beanshell"/> <param name = "script"> import org. apache. commons. validator. emailValidator; return EmailValidator. getInstance (); </param> </create>... </allow>

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.