jquery Ajax URL函数调用

时间:2013-06-28 04:39:58

标签: ajax jquery

这是我的Jquery Ajax部分: -

$.ajax({
    type: "GET",
    data: 'name=' + dept+"&emp=1",
    async: false,
    url: "master/loginCreateUser.jsp/getEmpName()",    //i m not able call thisgetEmpName Function call in this location
    success: function(data) {                    
        for(var item in data){
          $("#empName").append("<option>" + data[item] + "</option>");
        }                     
    }
 });

这是我的loginCreateUser.jsp页面:

<%!
public ArrayList<String> getEmpName() throws Exception { 
   ArrayList<String> emp = new  ArrayList(); %>          
   <% String s1 = request.getParameter("name"); %>
   <%! emp =  new UserRights().showEmp(s1); %> //i am not access this s1 variable on this location,it shows the error can't find symbol"
   <% 
     return emp;
}
%>

如何从jsp页面调用此功能?

1 个答案:

答案 0 :(得分:0)

<% String s1 = request.getParameter("name"); %>

Scriptlet属于服务方法体系。 s1,这里是服务方法的本地。无法从声明部分访问它。

<%!
public ArrayList<String> getEmpName() throws Exception { 
   ArrayList<String> emp = new  ArrayList();          
   String s1 = request.getParameter("name"); //Wouldn't work because the implicit request object is available only within the service method or a scriptlet.
   emp =  new UserRights().showEmp(s1);
   return emp;
}
%>

您可以将getEmpName()修改为:

<%!
    public ArrayList<String> getEmpName(String name) throws Exception { 
       ArrayList<String> emp = new  ArrayList();     
       emp =  new UserRights().showEmp(name); //showEmp() must return an ArrayList<String>
       return emp;
    }
%>

在scriptlet中调用方法。

<%
   String empName = getEmpName(request.getParameter("name"));

%>