本文介绍了没有显示问题,但不起作用-dwr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用dwr处理java-servlet中的ajax调用,

这是我的dwr.xml,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://getahead.org/dwr/dwr20.dtd">
<dwr>
    <allow>
        <create creator="new" javascript="TempCardServlet">
            <param name="class" value="com.slingmeadia.notifier.servlet.TempCardServlet"/>
        </create>
    </allow>
</dwr>

这是我的servlet文件,因此我称为

package com.slingmeadia.notifier.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class TempCardServlet extends HttpServlet {
 @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {


        String funtionType="";
        if(request.getParameter("functiontype")!=null){
            funtionType = (String)request.getParameter("functiontype");
        }
        if(funtionType.equals("logout")){
            processLogout(request, response);
        }else{

        }

    }
@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processLogout(request, response);
    }
    public Map sampleFill(int empid,String functiontype){
      System.out.println("functiontype : "+functiontype);
        Map employeeData = new LinkedHashMap();
        if(functiontype.equals("add")){
            employeeData.put("name", "Antony");
        }else{
            employeeData.put("name", "Antony");
            employeeData.put("cardnumber", "87896857852");
            employeeData.put("issuedate", "17/01/2012");
        }
        return employeeData;
    }


}

这就是我从jsp文件中调用方法的方式:

<script src='dwr/engine.js'></script>
        <script src='dwr/util.js'></script>
        <script src='dwr/interface/TempCardServlet.js'></script>

        <script>
            function getValues(id) {
                var empid = id.value;
                var optionValue = document.getElementById("selectedOption").value;
                TempCardServlet.sampleFill(empid,optionValue,{callback:setValues,async:false});
            }
            function setValues(tempcardMap) {
                if(tempcardMap !=null){
                    document.getElementById("empname").value=tempcardMap.name;
                    document.getElementById("tempcardnumber").value=tempcardMap.cardnumber;
                    document.getElementById("dateofissue").value=tempcardMap.issuedate;
                }
            }
</script>

这就是我如何调用javascript方法的方法:

<td width="55%"><input class="inputBoxes" type="text" name="empid" id="empid" onblur="getValues(this)" /></td>

似乎一切安排得很好,没有问题,但它没有用,也没有给予任何鼓舞.

我也尝试过这样

在网址中输入http://localhost:8080/acct/dwr/index.html

它提供了DWR已知的类的列表:当我尝试从浏览器打开类文件并提供一些示例输入但没有给出任何错误也没有输出时,我的类文件也存在.

请帮助我解决这个问题.

致谢.

解决方案

1.检查dwr路径

如果您要在WEB-INF中使用查看文件,则

<script src='dwr/engine.js'></script>
<script src='dwr/util.js'></script>
<script src='dwr/interface/TempCardServlet.js'></script>

可以通过这种方式进行引用.否则,您必须提供如下所示的正确路径

<script src='../dwr/engine.js'></script>
<script src='../dwr/util.js'></script>
<script src='../dwr/interface/TempCardServlet.js'></script>

Hi all i am using dwr to handle ajax calls in java-servlet,

this is what is my dwr.xml,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://getahead.org/dwr/dwr20.dtd">
<dwr>
    <allow>
        <create creator="new" javascript="TempCardServlet">
            <param name="class" value="com.slingmeadia.notifier.servlet.TempCardServlet"/>
        </create>
    </allow>
</dwr>

and this what is my servlet file and in that i call the

package com.slingmeadia.notifier.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class TempCardServlet extends HttpServlet {
 @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {


        String funtionType="";
        if(request.getParameter("functiontype")!=null){
            funtionType = (String)request.getParameter("functiontype");
        }
        if(funtionType.equals("logout")){
            processLogout(request, response);
        }else{

        }

    }
@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processLogout(request, response);
    }
    public Map sampleFill(int empid,String functiontype){
      System.out.println("functiontype : "+functiontype);
        Map employeeData = new LinkedHashMap();
        if(functiontype.equals("add")){
            employeeData.put("name", "Antony");
        }else{
            employeeData.put("name", "Antony");
            employeeData.put("cardnumber", "87896857852");
            employeeData.put("issuedate", "17/01/2012");
        }
        return employeeData;
    }


}

and this is how i call the method from jsp file :

<script src='dwr/engine.js'></script>
        <script src='dwr/util.js'></script>
        <script src='dwr/interface/TempCardServlet.js'></script>

        <script>
            function getValues(id) {
                var empid = id.value;
                var optionValue = document.getElementById("selectedOption").value;
                TempCardServlet.sampleFill(empid,optionValue,{callback:setValues,async:false});
            }
            function setValues(tempcardMap) {
                if(tempcardMap !=null){
                    document.getElementById("empname").value=tempcardMap.name;
                    document.getElementById("tempcardnumber").value=tempcardMap.cardnumber;
                    document.getElementById("dateofissue").value=tempcardMap.issuedate;
                }
            }
</script>

and this how i make a call to javascript method :

<td width="55%"><input class="inputBoxes" type="text" name="empid" id="empid" onblur="getValues(this)" /></td>

it seems all are good arranged and no issues but it is not working and do not give any excetpion also.

i tried to like this also

in url i typed http://localhost:8080/acct/dwr/index.html

it gives me the list of Classes known to DWR: and my class file also is there, when i tried to open the class file from browser and gave some sample input but it is not giving any error also no output.

Please help me to resolve this.

Regards.

解决方案

1.check the dwr path

if you are going to have the view files inside WEB-INF than

<script src='dwr/engine.js'></script>
<script src='dwr/util.js'></script>
<script src='dwr/interface/TempCardServlet.js'></script>

Refering this way will work.if not you have to give proper path like the below

<script src='../dwr/engine.js'></script>
<script src='../dwr/util.js'></script>
<script src='../dwr/interface/TempCardServlet.js'></script>

这篇关于没有显示问题,但不起作用-dwr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:20