weixin_33697898 2013-06-28 04:39 采纳率: 0%
浏览 35

jQuery Ajax URL函数调用

this is my Jquery Ajax Part:-

$.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>");
        }                     
    }
 });

and this is my loginCreateUser.jsp page:

<%!
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;
}
%>

How can I call this function from jsp page?

  • 写回答

1条回答 默认 最新

  • 撒拉嘿哟木头 2013-06-28 04:52
    关注
    <% String s1 = request.getParameter("name"); %>
    

    Scriptlets go under the body of service method. s1, here, is local to the service method. It cannot be accessed from the declaration part.

    <%!
    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;
    }
    %>
    

    You can modify your getEmpName() to this:

    <%!
        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;
        }
    %>
    

    And make the method call inside a scriptlet.

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

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?