ajax - Displaying JSON data in dropdown list in struts2 -


i doing code. struck @ 1 problem. want populate json data in select box in struts2.

what doing is..i sending ajax request on click of button , displaying form.

form has property display none. when click on button changes block.

but there 1 error coming whenever opening jsp page browser.

the requested list key 'categories' not resolved collection

my struts.xml

<?xml version="1.0" encoding="utf-8" ?> <!doctype struts public     "-//apache software foundation//dtd struts configuration 2.0//en"     "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.custom.i18n.resources" value="loginaction" />     <package name="default" extends="struts-default" namespace="/">         <action name="login" class="com.agents.cb.loginaction" >             <result name="success" type="redirect">welcome.jsp</result>             <result name="input">login.jsp</result>         </action>         <action name="register" method="register" class="com.agents.cb.loginaction"  >             <result name="success">login.jsp</result>         </action>     </package>     <package name="admin" extends="json-default" namespace="/admin">         <action name="addcategory" method="addcategory" class="com.type.user.admin"  >             <result type="json">                 <param name="excludenullproperties">true</param>                 <param name="excludeproperties">                     catname,catcode                 </param>              </result>         </action>         <action name="categories" method="categories" class="com.type.user.admin"  >             <result type="json">                 <param name="excludenullproperties">true</param>                 <param name="excludeproperties">                     catname,catcode,status                 </param>              </result>         </action>     </package> </struts> 

admin.java file

package com.type.user;  import java.io.printwriter;  import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import com.opensymphony.xwork2.actionsupport; import java.util.list; import java.util.arraylist; import java.util.map; import java.util.hashmap;  import com.type.product.*;  public class admin extends actionsupport {     private string catcode;     private string catname;     private httpservletrequest request;     private map<string, string> categories = new hashmap<string, string>();;      private string status;      public map<string, string> getcategories() {         return categories;     }      public void setcategories(map<string, string> categories) {         this.categories = categories;     }      public void setservletrequest(httpservletrequest request) {         this.request = request;     }      public string getcatcode() {         return catcode;     }      public void setcatcode(string catcode) {         this.catcode = catcode;     }      public string getcatname() {         return catname;     }      public void setcatname(string catname) {         this.catname = catname;     }      public string getstatus() {         return status;     }      public void setstatus(string status) {         this.status = status;     }      public string addcategory() {         product prod = new product();         boolean flag = prod.addcat(catcode, catname);         //boolean flag=false;         if (flag) {             status=catname+" added successfully.";             return success;         } else {             status="error occurred while adding "+catname;             return success;         }     }      public string categories(){         system.out.println("step 1");         product prod=new product();         categories=prod.getallcategories();         return success;     } } 

my script on jsp page

$(".add_sub_category").click(function(e){                 e.preventdefault();                 $.ajax({                     url : '/login/admin/categories',                     type : 'post',                     datatype : 'json',                     sucess : function(resp) {                         console.log(resp);                     }                 });                          }); 

please help. doing wrong? , why have problem.

you declared this

<package name="admin" extends="json-default" namespace="/admin">     <action name="categories" method="categories" class="com.type.user.admin"  > 

but trying call @

url : '/login/admin/categories', 

change path declared:

url : '/admin/categories', 

because login not defined anywhere part of namespace.

also pay attention when playing different namespaces...

hope helps


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -