DWR user management demo

Source: Internet
Author: User

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




DWR user management demo

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.