0

这是我的 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页面调用此函数?

4

1 回答 1

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"));

%>
于 2013-06-28T04:52:59.733 回答