java - Display a sublist using the list option selected -


i creating ecommerce website in java in have categories such clothing, books, electronics, etc. wish when choose category, e.g. electronics, should list sub-options such mobiles, tv, ipod, etc. how can accomplish this?

you can build categories class static getsubcategories() method returns set of sub-categories each possible category:

categories.java

import java.utils.list; import java.utils.arrays;  class categories {       private final statis categories categories = null;      private map<string, list<string>> subcategories = null;      private categories() {          subcategories = new hashmap<>();         subcategories.put("eletronics", arrays.aslist("mobiles", "tv", "ipod"));     }      public static categories getinstance() {         if (categories == null) {              categories = new categories();         }         return categories;     }      public static getsubcategories(string category) {         return subcategories.get(category);     } } 

assuming you've jsp page handle user input, can print subcatgories of category follows:

action.jsp

<%@ page contenttype="text/html; charset=iso-8859-1" language="java" %> <%     string category = request.getparameter("category");     list<string> subcategories = categories.getsubcategories(category); %> <html> <body> //print sub-categories subcategories : <%=subcategories%> </body> 


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -