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

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..**

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 :

<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 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

View Answers









Related Tutorials/Questions & Answers:

Ads