{"id":1681,"date":"2016-09-21T12:16:54","date_gmt":"2016-09-21T12:16:54","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=1681"},"modified":"2016-12-29T05:18:29","modified_gmt":"2016-12-29T05:18:29","slug":"displaying-bean-list-values-in-jsp-sp2","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/displaying-bean-list-values-in-jsp-sp2\/","title":{"rendered":"Displaying Bean List Values in JSP (sp2)"},"content":{"rendered":"<p><strong>DAOService.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class DAOService \r\n{\r\n\tprivate List&lt;Person&gt; arrPersons = new ArrayList&lt;Person&gt;(); \r\n\t\t\t\r\n\tpublic DAOService()\r\n\t{\r\n\t\t\r\n\t\tPerson objPerson = new Person();\r\n\t\tobjPerson.setName(&quot;Person 1&quot;);\r\n\t\tobjPerson.setLocation(&quot;Teynampet&quot;);\r\n\t\t\r\n\t\tarrPersons.add(objPerson);\r\n\t\t\r\n\t\tPerson objPerson2 = new Person();\r\n\t\tobjPerson2.setName(&quot;Person 2&quot;);\r\n\t\tobjPerson2.setLocation(&quot;TNagar&quot;);\r\n\t\t\r\n\t\tarrPersons.add(objPerson2);\r\n\t}\r\n\r\n\tpublic List getList()\r\n\t{\r\n\t\treturn this.arrPersons;\r\n\t}\r\n}\r\n<\/pre>\n<p><strong>ListPerson.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@Controller\r\n@RequestMapping(&quot;\/List&quot;)\r\npublic class ListPerson \r\n{\t\r\n\t@Autowired\r\n\tprivate DAOService objDAOService;\r\n\t\r\n\t@RequestMapping(&quot;\/PersonList&quot;)\r\n\tpublic String listPersons(Model model)\r\n\t{\r\n\t\tDAOService objDAOService = new DAOService();\r\n\t\t\r\n\t\tmodel.addAttribute(&quot;personList&quot;, this.objDAOService.getList());\r\n\t\t\r\n\t\treturn &quot;display_list&quot;;\r\n\t}\r\n}\r\n<\/pre>\n<p><strong>display_list.jsp<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;title&gt;Insert title here&lt;\/title&gt;\r\n&lt;%@ taglib uri=&quot;http:\/\/java.sun.com\/jsp\/jstl\/core&quot; prefix=&quot;c&quot; %&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\t\r\n\t&lt;table&gt;\r\n\t\t&lt;c:forEach items=&quot;${personList}&quot; var=&quot;objPerson&quot;&gt; \r\n\t\t\t&lt;tr&gt;\r\n\t\t\t\t&lt;td&gt;${objPerson.name}&lt;\/td&gt;\r\n\t\t\t\t&lt;td&gt;${objPerson.location}&lt;\/td&gt;\r\n\t\t\t&lt;\/tr&gt;\r\n\t\t&lt;\/c:forEach&gt;\r\n\t&lt;\/table&gt;\r\n&lt;\/body&gt;\r\n<\/pre>\n<p><strong>applicationContext.xml<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;bean name=&quot;DAOService&quot; class=&quot;com.mugil.controls.DAOService&quot;&gt;&lt;\/bean&gt;\r\n<\/pre>\n<p><strong>pom.xml<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;dependency&gt;\r\n    &lt;groupId&gt;javax.servlet&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;jstl&lt;\/artifactId&gt;\r\n    &lt;version&gt;1.2&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n<\/pre>\n<p><strong>Method Arguments in Controller<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@Controller\r\n@RequestMapping(&quot;\/Control1&quot;)\r\npublic class TestController \r\n{\t\r\n\t@RequestMapping(&quot;\/Control2&quot;)\t\t\r\n\tpublic String TestMe(HttpSession session, HttpServletRequest request)\r\n\t{\r\n\t\trequest.setAttribute(&quot;name&quot;, &quot;Mugil Vannan&quot;);\r\n\t\tsession.setAttribute(&quot;Test&quot;, &quot;TestValue&quot;);\r\n\t\tSystem.out.println(&quot;1&quot;);\r\n\t\treturn &quot;hello&quot;;\r\n\t}\r\n\t\r\n\t@RequestMapping(value=&quot;\/Control2&quot;, method=RequestMethod.POST)\r\n\tpublic String TestMe2(HttpSession session, HttpServletRequest request)\r\n\t{\r\n\t\tSystem.out.println(session.getAttribute(&quot;Test&quot;));\r\n\t\tSystem.out.println(request.getParameter(&quot;cboArea&quot;));\t\t\r\n\t\treturn &quot;display&quot;;\r\n\t}\r\n}\r\n<\/pre>\n<p><strong>Alternate of HttpServletRequest request<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@RequestMapping(value=&quot;\/Control2&quot;, method=RequestMethod.POST)\r\npublic String TestMe2(HttpSession session, @RequestParam(&quot;cboArea&quot;) String Area)\r\n{\r\n  System.out.println(session.getAttribute(&quot;Test&quot;));\r\n  System.out.println(Area);\t\t\r\n  return &quot;display&quot;;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>DAOService.java public class DAOService { private List&lt;Person&gt; arrPersons = new ArrayList&lt;Person&gt;(); public DAOService() { Person objPerson = new Person(); objPerson.setName(&quot;Person 1&quot;); objPerson.setLocation(&quot;Teynampet&quot;); arrPersons.add(objPerson); Person objPerson2 = new Person(); objPerson2.setName(&quot;Person 2&quot;); objPerson2.setLocation(&quot;TNagar&quot;); arrPersons.add(objPerson2); } public List getList() { return this.arrPersons; } } ListPerson.java @Controller @RequestMapping(&quot;\/List&quot;) public class ListPerson { @Autowired private DAOService objDAOService; @RequestMapping(&quot;\/PersonList&quot;) public String&hellip; <a href=\"https:\/\/codethataint.com\/blog\/displaying-bean-list-values-in-jsp-sp2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189],"tags":[],"class_list":["post-1681","post","type-post","status-publish","format-standard","hentry","category-form-elements-spring"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=1681"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1681\/revisions"}],"predecessor-version":[{"id":1989,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1681\/revisions\/1989"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=1681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=1681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=1681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}