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

Discussion in 'Java' started by Vitthal Bhat via JavaKB.com, Jan 25, 2005.

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

    --
    Message posted via http://www.javakb.com
    Vitthal Bhat via JavaKB.com, Jan 25, 2005
    #1
    1. Advertising

  2. Vitthal Bhat via JavaKB.com

    Deepak Guest

    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
    Vitthal Bhat via JavaKB.com wrote:
    > 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
    >
    > --
    > Message posted via http://www.javakb.com
    Deepak, Jan 25, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF1bA==?=

    remove a selection from a dropdown list box.

    =?Utf-8?B?UGF1bA==?=, Apr 26, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    650
    Chris
    Apr 28, 2005
  2. Mike
    Replies:
    1
    Views:
    793
  3. =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?=

    Dropdown List - Check if value exists in list prior to selection

    =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?=, Mar 10, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    1,972
    =?Utf-8?B?QnJlbmRlbg==?=
    Mar 20, 2007
  4. Adrian
    Replies:
    1
    Views:
    207
    Bullschmidt
    Feb 18, 2004
  5. chris_huh
    Replies:
    3
    Views:
    135
Loading...

Share This Page