Facing problem in displaying dropdown menu(list box with single selection)in JSP

  • Thread starter Vitthal Bhat via JavaKB.com
  • Start date
V

Vitthal Bhat via JavaKB.com

hi Everybody,

I am new to struts.
I want to display a dropdown window in JSP page.


My JSP Code IS (Site1.jsp is name of the form name)

<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>



<HTML>
<BODY>

<html:form action="Site1">


<TD class="label" colspan="1" style="color:#000000"><bean:message key="Site1.phCountryCode" />
</TD>

<td>
<html:select property="phCountryCode">



<html:eek:ptions collection="phcountry" property="value" labelProperty="label"/>
</html:select>

--------------------------------------------------------
--- my phcountry bean class is--



public class phcountry extends ActionForm{

private int id;
private String phcountryname;


public phcountry( int id, String phcountryname ) {
this.id = id;
this.phcountryname = phcountryname;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getphcountryname() {
return phcountryname;
}
public void setphcountryname(String phcountryname) {
this.phcountryname = phcountryname;
}
}

-----------------------------------------------------------------

my helper Class name is SiteHelper as given below


public class SiteHelper
{
public Collection getphcountry() {

ArrayList list = new ArrayList(3);
list.add( new phcountry( 93, "Afghanistan"));
list.add( new phcountry( 91, "India"));
list.add( new phcountry( 01, "U.S.A"));
return list;
}

}

_________________________________
my action class is SiteAction as given below


import java.util.Collection;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class SiteAction extends Action
{
private static Log log = LogFactory.getLog(SiteAction.class);

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{

SiteHelper isitehelper=new SiteHelper();
Collection phcountry = isitehelper.getphcountry();
request.setAttribute( "phcountry", phcountry );

return mapping.findForward("success");

}
}

i comple the program using Ant tool and giving message Build Successfully

once i run the jsp page thru Tomcat 5.0 its giving error like.


description: The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Cannot find ActionMappings or ActionFormBeans collection
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl .java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.j ava:758)
org.apache.jsp.Site1_jsp._jspService(Site1_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


root cause

javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:711)
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:419)
org.apache.jsp.Site1_jsp._jspx_meth_html_form_0(Site1_jsp.java:115)
org.apache.jsp.Site1_jsp._jspService(Site1_jsp.java:89)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.25 logs.


So please help me to populate Drop down box in my JSP page
 
D

Deepak

Hi Vitthal,

Are you able to render your jsp file without the drop down? If you look
at the stack trace, the error is while rendering the form tag and no
the options tag. I haven't worked with the latest release of struts,
but I recall that you need to have a name property in the form tag and
this name needs to be mapped to a form bean class in the
struts-config.xml. You also need to make sure that your
struts-config.xml file is properly setup.

Let me know if this helps

regards
Deepak said:
hi Everybody,

I am new to struts.
I want to display a dropdown window in JSP page.


My JSP Code IS (Site1.jsp is name of the form name)

<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>



<HTML>
<BODY>

<html:form action="Site1">


<TD class="label" colspan="1" style="color:#000000"><bean:message key="Site1.phCountryCode" />
</TD>

<td>
<html:select property="phCountryCode">



<html:eek:ptions collection="phcountry" property="value" labelProperty="label"/>
</html:select>

--------------------------------------------------------
--- my phcountry bean class is--



public class phcountry extends ActionForm{

private int id;
private String phcountryname;


public phcountry( int id, String phcountryname ) {
this.id = id;
this.phcountryname = phcountryname;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getphcountryname() {
return phcountryname;
}
public void setphcountryname(String phcountryname) {
this.phcountryname = phcountryname;
}
}

-----------------------------------------------------------------

my helper Class name is SiteHelper as given below


public class SiteHelper
{
public Collection getphcountry() {

ArrayList list = new ArrayList(3);
list.add( new phcountry( 93, "Afghanistan"));
list.add( new phcountry( 91, "India"));
list.add( new phcountry( 01, "U.S.A"));
return list;
}

}

_________________________________
my action class is SiteAction as given below


import java.util.Collection;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class SiteAction extends Action
{
private static Log log = LogFactory.getLog(SiteAction.class);

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{

SiteHelper isitehelper=new SiteHelper();
Collection phcountry = isitehelper.getphcountry();
request.setAttribute( "phcountry", phcountry );

return mapping.findForward("success");

}
}

i comple the program using Ant tool and giving message Build Successfully

once i run the jsp page thru Tomcat 5.0 its giving error like.


description: The server encountered an internal error () that
prevented it from fulfilling this request.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top