Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Struts2...problem in JSP..unable to get the values for menuTitle!!!

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Struts2...problem in JSP..unable to get the values for menuTitle!!!

    Hello everyone...

    i'm trying to make a dynamic menu from database in struts2...n m fairly new in this framework.. there is some problem in this project...my Jsp is displaying the menuId from database but not the menuTitle...where as its working fine for menuId..
    i've attached my war file made in Eclipse IDE as well!!!

    name of attached WAR file: Basic.rar
    name of attached project(without WAR) : Basic_withoutWAR.rar






    here's the content of my project :


    ConnectionProvider.java:


    package pkg;
     
    import java.sql.Connection;
    import java.sql.DriverManager;
     
     
    public class ConnectionProvider 
    {
    public static Connection getConnection(){
    Connection con=null;
    try{
    Class.forName("org.postgresql.Driver");
    con=DriverManager.getConnection("jdbc:postgresql://localhost:5433/labway","postgres","sachin");
    }
    catch(Exception e){
    System.out.println(e);
    }
    return con;
    }
    }




    DAO.java:


    package pkg;
     
     
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.util.*;
     
     
    public class DAO 
    {
    public List<MenuList> fetch(){
    try{
    System.out.println("\nInside DAO fetch... "); 
    Connection con=ConnectionProvider.getConnection();
    PreparedStatement stmt=con.prepareStatement("select * from application where application_id in (select distinct application_id from applicationmenu order by application_id)");
    System.out.println("\nstatement Prepared....");
    ResultSet rs=stmt.executeQuery();
    System.out.println("\nExecuting 1st query...");
    MenuList menulist;
    List<MenuList> list=new ArrayList<MenuList>();
    while(rs.next())
    {
    menulist=new MenuList();
    menulist.setmenuId(rs.getString(1));
    System.out.println("\ninside while of DAO,setting menuId as... "+rs.getString(1)+" " +menulist.getMenuId())  ;
    menulist.setmenuTitle(rs.getString(3));
    System.out.println("\ninside while of DAO...setting menuTitle as... "+rs.getString(3)+" "+menulist.getmenuTitle())  ;
    list.add(menulist);
    }
    return list; 
    }
    catch(Exception e)
    {
    System.out.println(e);
    }
    return null;
    }
    }



    MenuList.java :




    package pkg;
     
     
     
     
    public class MenuList {
    String menuId;
    String menuTitle;
     
     
    public MenuList()
    {
    super();
    }
    public MenuList(String menuId,String menuTitle)
    {
    super();
    this.menuId=menuId;
    this.menuTitle=menuTitle;
     
     
    }
    public String getMenuId()
    {
    System.out.println("Inside getMenuId() of MenuList class...menuId is "+menuId);
    return menuId;
    }
    public String getmenuTitle()
    { 
    System.out.println("Inside getmenuTitle() of MenuList class...menu title is "+menuTitle);
    return menuTitle;
    }
     
     
    public void setmenuId(String menuId) 
    {
    System.out.println("\nInside setmenuId of MenuList class..set menuId= "+menuId);
    this.menuId = menuId;
    } 
    public void setmenuTitle(String menuTitle) 
    {
    System.out.println("\nInside setmenuTitle of MenuList class..set menuTitle= "+menuTitle);
    this.menuTitle = menuTitle;
    } 
     
     
    }




    MenuListAction.java :





    package pkg;
    import java.util.*;
    import com.opensymphony.xwork2.ActionSupport;
     
     
    public class MenuListAction extends ActionSupport
     
     
    {
    private MenuList menulist;
    private List<MenuList> menulistlist;
    DAO dao=new DAO();
    public String execute()
    {
    menulistlist=dao.fetch();
    System.out.println("\nInside exceute of MenuListAction..");
    return "success";
    }
    public MenuList getMenulist() 
    {
    System.out.println("Inside getMenulist of MenuListAction...");
    return menulist;
    }
    public void setMenulist(MenuList menulist) 
    {
    System.out.println("Inside setMenulist...");
    this.menulist = menulist;
    }
    public List<MenuList> getMenulistlist() 
    {
    System.out.println("Inside getMenulistlist of MenuListAction...");
    return menulistlist;
    }
    public void setMenulistlist(List<MenuList> menulistlist) 
    {
    System.out.println("\nInside setMenulistlist...");
    this.menulistlist = menulistlist;
    }
     
     
    }






    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.devMode" value="true"></constant>
     
     
    <package name="Basic" extends="struts-default" namespace="/">
     
    <action name="hello" class="pkg.MenuListAction" method="execute">
     
     
    <result name="success" >/menujsp.jsp</result>
     
     
    </action>
     
     
    </package>
    </struts>



    web.xml :




    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
     
     
      <filter>
      <filter-name>struts2</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      </filter-class>
      </filter>  
      <filter-mapping>
      <filter-name>struts2</filter-name>
       <url-pattern>/*</url-pattern>
      </filter-mapping>
      </web-app>






    index.jsp :




    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
       pageEncoding="ISO-8859-1"%>
       <%@taglib uri="/struts-tags" prefix="s" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <head><title>DYNAMIC DROPDOWN MENU</title></head>
    <body><br><br><center>
     
     
    <a href="<s:url action='hello'/>">Home Page</a>
     
     
    </center>
    </body>
    </html>



    menujsp.jsp :


    <%@ taglib prefix="s" uri="/struts-tags"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <body>
    <h3>EMPLOYMENT EXCHANGE Test Page</h3>
    <table cellpadding="0" cellspacing="0" border="2">
     
     
    <tr><th>MenuID</th><th>MenuTitle</th></tr>
     
     
    <s:iterator value="menulistlist" var="menulist"> 
    <tr>
    <td><s:property value="menuId"/></td>
     
     
    <td><s:property value="menuTitle"/></td>           
     
     
    </tr>
     
     
    </s:iterator>
    </table>
       </body>
     
     
    </html>







    Following is the the output of my console :


    Inside DAO fetch...


    statement Prepared....


    Executing 1st query...


    Inside setmenuId of MenuList class..set menuId= 0000000001
    Inside getMenuId() of MenuList class...menuId is 0000000001


    inside while of DAO,setting menuId as... 0000000001 0000000001


    Inside setmenuTitle of MenuList class..set menuTitle= Registration
    Inside getmenuTitle() of MenuList class...menu title is Registration


    inside while of DAO...setting menuTitle as... Registration Registration


    Inside setmenuId of MenuList class..set menuId= 0000000002
    Inside getMenuId() of MenuList class...menuId is 0000000002


    inside while of DAO,setting menuId as... 0000000002 0000000002


    Inside setmenuTitle of MenuList class..set menuTitle= Renewal
    Inside getmenuTitle() of MenuList class...menu title is Renewal


    inside while of DAO...setting menuTitle as... Renewal Renewal


    Inside setmenuId of MenuList class..set menuId= 0000000003
    Inside getMenuId() of MenuList class...menuId is 0000000003


    inside while of DAO,setting menuId as... 0000000003 0000000003


    Inside setmenuTitle of MenuList class..set menuTitle= EMI
    Inside getmenuTitle() of MenuList class...menu title is EMI


    inside while of DAO...setting menuTitle as... EMI EMI


    Inside exceute of MenuListAction..
    Inside getMenulistlist of MenuListAction...
    Inside getMenuId() of MenuList class...menuId is 0000000001
    Inside getMenuId() of MenuList class...menuId is 0000000001
    Inside getMenuId() of MenuList class...menuId is 0000000001
    Inside getMenuId() of MenuList class...menuId is 0000000002
    Inside getMenuId() of MenuList class...menuId is 0000000002
    Inside getMenuId() of MenuList class...menuId is 0000000002
    Inside getMenuId() of MenuList class...menuId is 0000000003
    Inside getMenuId() of MenuList class...menuId is 0000000003
    Inside getMenuId() of MenuList class...menuId is 0000000003
    Inside getMenulistlist of MenuListAction...
    Inside getMenuId() of MenuList class...menuId is 0000000001
    Inside getMenuId() of MenuList class...menuId is 0000000002
    Inside getMenuId() of MenuList class...menuId is 0000000003
















    when i'm givin
     <td><s:property value="menuTitle"/></td>
    in my jsp...then it should call getmenuTitle() from MenuList class..but thats not happening... but all this is working for "menuId"...





    Thanking you,
    Sachin

    Attached Files Attached Files


  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Struts2...problem in JSP..unable to get the values for menuTitle!!!

    i have solved my problem....The names of getters and setters are dictated by the JavaBean specification which allows us to use reflection to look up object properties at run time.

Similar Threads

  1. Simplest Problem but i am unable to understand it, WHY???
    By Mr.777 in forum Object Oriented Programming
    Replies: 11
    Last Post: October 26th, 2011, 03:28 AM
  2. struts2 is better or spring?
    By the light in forum Web Frameworks
    Replies: 0
    Last Post: June 26th, 2011, 11:10 AM
  3. MultiLevel Combobox in Struts2
    By tcstcs in forum Web Frameworks
    Replies: 0
    Last Post: May 23rd, 2011, 06:47 AM
  4. unable to get values for modification
    By javaking in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: September 17th, 2010, 05:27 AM
  5. Plugin the struts2 framework
    By kalees in forum Web Frameworks
    Replies: 1
    Last Post: January 15th, 2010, 01:19 AM