dwr 실례

4513 단어 자바jspxmlWebDWR
1、  dwr   jar dwr.jar

2、    web  ,   dream, jar   lib 

3、  web.xml,  :

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 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_4.xsd">
 
  <!--   dwr    -->
   <servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
   </servlet>
   <servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
   </servlet-mapping>
   
   <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
4、  Java   :

package com.main;
public class Check {
 public boolean check(String name,String password){
  if(name.endsWith("123") && password.endsWith("123"))
   return true;
  else
   return false;
 }
}
5、  dwr.xml,     Java ,  :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr30.dtd">
<dwr>
 <allow>
  <create creator="new" javascript="Check"><!-- javascrit   ,dwr     Check.js,   js        Check   Check       -->
   <param name="class" value="com.main.Check"></param>
  </create>
  <create creator="new" javascript="Hello">
   <param name="class" value="com.main.Hello"></param>
  </create>
 </allow>
</dwr>

6、  jsp  ,  :

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>DWR  </title>
  <!--   dwr   js   -->
  <script type="text/javascript" src="/dream/dwr/engine.js"></script>
  <script type="text/javascript" src="/dream/dwr/util.js"></script>
  <!--      -->
  <!--    dwr    javascript  , dwr     js   -->
  <script type="text/javascript" src="/dream/dwr/interface/Check.js"></script>
  <script type="text/javascript">
   function login(){
    var name = dwr.util.getValue("name");
    var password = dwr.util.getValue("password");
    Check.check(name,password,function (ok){//  ok Check   check(String name,String password)    
     if(ok==true){
      document.getElementById("loginDiv").style.visibility = "hidden";
      document.getElementById("resultDiv").style.visibility = "visible";
      document.getElementById("resultDiv").innerHTML = "<font color=red size=8>   ,    !</font>";
     }else{
      document.getElementById("resultDiv").style.visibility = "visible";
      document.getElementById("resultDiv").innerHTML = "<font color=red size=8>        !</font>";
     }
    });
   }
  </script>
  </head>
 
  <body>
    <div id="resultDiv" style="border-color: green;border-width: 1px;border-style: outset;width: 50%;visibility: hidden;">
    </div>
    <div id="loginDiv"  style="visibility: visible;">
       :<input type="text" name="name" id="name">
     <br><br>
       :<input type="password" name="password" id="password">
     <br><br>
     <input type="button"  value="  " onclick="login()">
     </div>
  </body>
</html>

 

좋은 웹페이지 즐겨찾기