title: How to design side menu bar from json file using spring mvc
body: <p>Am trying to  design a side menu in jsp home page using json file with spring mvc below is my three files, jsp page contains a code that the way which i am looking to design side menu the json file contains menu and sub menu data, in the spring controller i read json file and  validate the user after validation i have send the data to jsp which i am getting from json file and make its menu and sub menu
  two different menu as r1 and r2</p>
  
  <p>here what i am facing the problem is how to json data from spring controller to jsp and make it as menu and sub menu</p>
  
  <pre><code>    user 
        adduser
        deleteuser
        updateuser
  job
  add job
  delete job
  update job
  </code></pre>
  
  <p><strong>jsp</strong></p>
  
  <pre><code>&lt;li&gt;
                          &lt;a href="#"&gt;&lt;!-- &lt;i class="fa fa-wrench fa-fw"&gt;&lt;/i&gt; --&gt;User&lt;span class="fa arrow"&gt;&lt;/span&gt;&lt;/a&gt;
                          &lt;ul class="nav nav-second-level"&gt;
                              &lt;li&gt;
                                  &lt;a href="javascript:void(0)"&gt;add user&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;a href="javascript:void(0)"&gt;delete user&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;a href="javascript:void(0)"&gt;update user&lt;/a&gt;
                              &lt;/li&gt;
  
                          &lt;/ul&gt;
                          &lt;!-- /.nav-second-level --&gt;
                      &lt;/li&gt;
  
                      &lt;li&gt;
                          &lt;a href="#"&gt;&lt;!-- &lt;i class="fa fa-wrench fa-fw"&gt;&lt;/i&gt; --&gt;job&lt;span class="fa arrow"&gt;&lt;/span&gt;&lt;/a&gt;
                          &lt;ul class="nav nav-second-level"&gt;
                              &lt;li&gt;
                                  &lt;a href="javascript:void(0)"&gt;add job&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;a href="javascript:void(0)"&gt;delete job&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;a href="javascript:void(0)"&gt;update job&lt;/a&gt;
                              &lt;/li&gt;
  
                          &lt;/ul&gt;
                          &lt;!-- /.nav-second-level --&gt;
                      &lt;/li&gt;
  </code></pre>
  
  <p><strong>Json file</strong>  </p>
  
  <pre><code>{
      "userid": "abc",
      "roles": ["admin"],
      "sidebar":  
      {           
                  "job": ["addjob", "updatejob", "deletejob"]
              ,
  
                  "user": ["adduaser", "deleteuser", "updateuser"]
  
  
      }   
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code> @RequestMapping(value = "/authenticateLogin", method = RequestMethod.POST)
              public   String loginAuthentication(HttpServletRequest request) {       
      String username=request.getParameter("userName");       
      JSONParser parser = new JSONParser();
      try {
          Object obj = parser.parse(new FileReader("d:\\test.json"));
          JSONObject jsonObject = (JSONObject) obj;
  
          String userID1 = (String) jsonObject.get("userid");
          if (username.equals(userID1)) {
              JSONArray rolesArray = (JSONArray) jsonObject.get("roles");
              String role = (String) rolesArray.get(0);
              if (role.equals("admin")) {
  
                  JSONObject sideContent = (JSONObject) jsonObject.get("sidebar");
                  JSONArray job = (JSONArray) sideContent.get("job");
                  JSONArray user = (JSONArray) sideContent.get("user");
  
                  ArrayList&lt;String&gt; jobArrayList = new ArrayList&lt;String&gt;();
                  ArrayList&lt;String&gt; userArrayList = new ArrayList&lt;String&gt;();
  
                  Iterator&lt;String&gt; iterator1 = job.iterator();
                  while (iterator1.hasNext()) {                       
                      jobArrayList.add(iterator1.next());
                  }
                  Iterator&lt;String&gt; iterator2 = user.iterator();
                  while (iterator2.hasNext()) {                       
                      userArrayList.add(iterator2.next());
                  }                   
                  return "";
              } 
  
  
              if(role.equals("user"))
              {
                  JSONObject sideContent = (JSONObject) jsonObject.get("sidebar");
                  JSONArray job = (JSONArray) sideContent.get("job");
                  ArrayList&lt;String&gt; jobArrayList = new ArrayList&lt;String&gt;();
                  Iterator&lt;String&gt; iterator1 = job.iterator();
                  while (iterator1.hasNext()) {                       
                      jobArrayList.add(iterator1.next());
                  }                   
                  return "";
              }
          }           
  
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      } catch (ParseException e) {
          e.printStackTrace();
      }
  
  
      return "Error";
  
  }
  </code></pre>