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

Ads

 
 
 

Share on Google+Share on Google+

sachin negi
Struts2...problem in JSP..unable to get the values for menuTitle!!!
0 Answer(s)      5 years and 3 months ago
Posted in : Struts

**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"%>
       <[email protected] 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

Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
Tutorials   
Java Spring Hibernate Struts Training Dynamic tabs in struts 1.2 Unable to upload a file to mysql database using struts1 Pagination in struts 2 struts2 filterdispatcher is deprecated please use the new filters viewing How to add struts2 dependency in Maven? Struts Exception Handling can you check below code if any erors multimedia how to display the value of termcell name in label class not found exception Where to learn Struts 2? dropdown cacheing Upload and Download Large files in jsp What is Struts 2 framework struts and hibernate based health care project source code struts and hibernate based health care project source code Struts 2 Integration with Struts 1 About captcha of strut2 About captcha of strut2 Which is the good website for struts 2 tutorials? advance java source code source code In Struts 2 how to pass the Struts struts internationalization for Korean language struts2 Struts2 and Hibernate Fetch Data Base Value Struts2 and Hibernate Fetch Data Base Value Struts2 and Hibernate i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse Struts2 and Hibernate Struts2 and Hibernate Struts2 validation Procedure Struts2 validation Procedure Struts2 validation Procedure Struts2 validation Procedure Struts 2 action-validation.xml not loading Struts-2 and Ajax integration STRUTS QUESTION conerting web project into .exe file About Select tag ScartApplication aplicacion ecommerce struts 1.3 struts 1.3 sms prob Need to know struts1 all jar file names struts with hibernate

Ads

 
Advertisement null

Ads