Drop-down in JSP using a bean as back-end

Hi everyone,
I like to create a dynamic drop-down (reading from a database) using JSP but accessing a bean. My code on the bean is:
public void DepartmentName() {
try
stmt1 = tConnection.createStatement();
rs1 = stmt1.executeQuery ("select DEPT_NAME from DEPARTMENT");
while ( rs1.next() )
String DptName = rs1.getString("DEPT_NAME");
System.out.println(DptName);
Can anybody tell me how to call this DepartmentName bean in JSP? So far my JSP looks like this...
<table width="100%"><tr>
<form action="next.jsp" method="POST">
<input type="hidden" name="type" value="listemp">
<td width="100">
<b>Department</b></td>
<td wifth="100">
<SELECT name=cust multiple size=4>
<option>??????? HELP ???????????</option>
</SELECT>
</td>
<td><input type="submit" value="Submit" name="dept">
</td></tr></table>
Many thanks.

First you need to modify your bean to return some sort of data structure of String objects. How about a Vector? Then you could call Vector.elements() on the return statement of the DepartmentName() method, like this...
public Enumeration DepartmentName()
  Vector myVector = new Vector(0);
  while(rs.next())
    myVector.add(rs.getString(1));
  return myVector.elements();
}Then in your JSP you'll need to use the JSP useBean tag
<jsp:useBean id="myBean" class="com.myco.myapp.MyBean" scope="page|request|session|application" />And before the option tag call the bean and get the enumeration of String objects, then loop through them like this:
while(enum.hasMoreElements())
  out.println(((String) enum.nextElement()));
}

Similar Messages

  • Is there a way to filter a drop down list by using the result main data display from"GetUserProfileByName" when open the form.

    Hi 
    Is there a way to filter a drop down list by using the result main data display from"GetUserProfileByName" when open the form?
    The second source has a huge list of company names that can be narrrow by email work. 
    background:SP 2010 and Infopath 2010
    CRISTINA&amp MICROSOFT Forum

    I'm not sure if I understood your question clearly but here is a good resource on how to get attributes from "GetUserProfileByName" web services:
    http://blog.mangroveweb.com/pre-populating-an-infopath-from-with-mysql-data-using-a-net-web-service/using-sharepoints-getuserprofilebyname-web-service-to-retrieve-ad-account-information/
    Regarding filtering dropdown list then this could be done by applying form on-load rules. 
    Hope this helps

  • Populate drop down on pageload using struts

    How can i populate my dropdown box from database on pageload event by using struts

    <html:select name="beanName" property="someProperty">
    <html:optionsCollection name="beanName" property="dropDownProperty" label="drop down Label" value="dropdown value"/>
    </html:select>Here the bean name is the Form bean which contains the drop down list and selected value.

  • Populating a Drop down menu JSP form

    How to go about populating a drop-down form from Oracle Database using JSP?
    I have the connecting to the Oracle Database running. I also can query forms, but i can't create a drop-down menu form.

    Start the dropdown box with the regular select tags "<select name=this>"
    Then open a JSP block and get a resutlset, loop through the resultset and and put the values from the resutlset into the <option> tags for the HTML.
    Example
    out.println("<option value=\"" + rs.getString(1) + "\">" + rs.getString(1) + ">");
    Then close the loop and that should populate a dropdown within the html form.

  • Passing database table values to drop down list list using "vrm_set_values"

    DEar Experts,
    How can we pass database travel to drop down list using vrm_set_value call function.
    Looking forward for advise from you experts .
    REgards
    CHandan

    Dear Anubhab,
    Thanks for your suggestion,
    Plz see my code:
    Type-pools: vrm.
    DATA: it_zlt_mita       TYPE STANDARD TABLE OF Zlt_mita,
               wa_zlt_mita    TYPE zlt_mita,
               it_vrm              TYPE vrm_values with header line .
    Selection-Screen: Begin of Block b1 With Frame Title text-001.
      Parameters:
        p_mitar            Type Zlt_mita-M1 as listbox visible length 20 user-command zcc01 obligatory,
        p_mitarn          Type Zlt_mita-M2.
    Selection-Screen : End of Block b1.
    AT SELECTION-SCREEN OUTPUT.
       Select * From ZLT_mita INTO CORRESPONDING FIELDS OF TABLE it_zlt_mita.
      LOOP at it_zlt_mita into wa_zlt_mita.
         it_vrm-key   = wa_zlt_mita-m2.
         it_vrm-text  = wa_zlt_mita-m1.
         APPEND it_vrm.
         Clear: it_vrm, wa_zlt_mita.
      ENDLOOP.
                     CALL FUNCTION 'VRM_SET_VALUES'
                       EXPORTING
                         id                    = 'P_mitar'
                         values                =  it_vrm[]
    *                  EXCEPTIONS
    *                    ID_ILLEGAL_NAME       = 1
    *                    OTHERS                = 2
                     IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
                     ENDIF.
    Data: dynfields type table of dynpread with header line.
         dynfields-fieldname = 'p_mitar'.
          Append dynfields.
    CALL FUNCTION 'DYNP_VALUES_READ'
      EXPORTING
        dyname                               = sy-cprog
        dynumb                               = 1000    " can I use sy-dynnr here
    *   TRANSLATE_TO_UPPER                   = ' '
    *   REQUEST                              = ' '
    *   PERFORM_CONVERSION_EXITS             = ' '
    *   PERFORM_INPUT_CONVERSION             = ' '
    *   DETERMINE_LOOP_INDEX                 = ' '
    *   START_SEARCH_IN_CURRENT_SCREEN       = ' '
    *   START_SEARCH_IN_MAIN_SCREEN          = ' '
    *   START_SEARCH_IN_STACKED_SCREEN       = ' '
    *   START_SEARCH_ON_SCR_STACKPOS         = ' '
    *   SEARCH_OWN_SUBSCREENS_FIRST          = ' '
    *   SEARCHPATH_OF_SUBSCREEN_AREAS        = ' '
      tables
        dynpfields                           =  dynfields
    * EXCEPTIONS
    *   INVALID_ABAPWORKAREA                 = 1
    *   INVALID_DYNPROFIELD                  = 2
    *   INVALID_DYNPRONAME                   = 3
    *   INVALID_DYNPRONUMMER                 = 4
    *   INVALID_REQUEST                      = 5
    *   NO_FIELDDESCRIPTION                  = 6
    *   INVALID_PARAMETER                    = 7
    *   UNDEFIND_ERROR                       = 8
    *   DOUBLE_CONVERSION                    = 9
    *   STEPL_NOT_FOUND                      = 10
    *   OTHERS                               = 11
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'DYNP_VALUES_UPDATE'
      EXPORTING
        dyname                     = sy-cprog
        dynumb                     = 1000
      tables
        dynpfields                 = dynfields
    * EXCEPTIONS
    *   INVALID_ABAPWORKAREA       = 1
    *   INVALID_DYNPROFIELD        = 2
    *   INVALID_DYNPRONAME         = 3
    *   INVALID_DYNPRONUMMER       = 4
    *   INVALID_REQUEST            = 5
    *   NO_FIELDDESCRIPTION        = 6
    *   UNDEFIND_ERROR             = 7
    *   OTHERS                     = 8
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    PLZ SUGGEST ME IF ANYWHERE I WENT WRONG IN MY CONCEPT AS PER YOUR SUGGESTION.
    Looking forward for your further guidance.
    Regards
    Chandan

  • JSP using a bean to do output?

    One thing I haven't seen much mention of is the possibility of using a Java Bean to
    do some output for a JSP. I'm porting a page I wrote a while back that uses a
    JHTML page to call a servlet which is just a thin wrapper around a bean which
    actually writes the HTML output (the bean is actually a network client to a server
    that generates the HTML page). The natural line of attack seems to be to have a
    JSP call the bean which will write the output, but I haven't seen mention of that
    technique anywhere and wonder why I'm so strange in thinking of this. The bean
    method to do the output currently takes a PrintWriter as a parameter to output to,
    but that can be changed to something similar if desired.
    Can anyone give me a snippet of code that would best implement taking the output
    stream for a JSP page and passing it to a bean for output?
    Thanks
    Steve

    eh? It sounds like your bean is doing all the output? If that's the case, then why do you want to use a JSP? - use a servlet as you already are.
    If you have a bean declared in the page and you just want to pass it the page's output stream to output part of the pages content, then use this:
    <jsp:useBean id='myBean' class='com.mycompany.MyBeanClass'/>
    <%
      PrintWriter beanOut = new PrintWriter(out);
      myBean.writeContent(beanOut);
      beanOut.close()
    %>
      ...where writeContent is your method that takes a PriontWriter. out is a JspWriter, which extends Writer, so you need to create a PrintWriter from it. You may or may not need to close/flush the PrintWriter deppending upon your bean implementation.

  • The "New Tab" function does not work either from the tab bar, the File drop down menu or using CTRL+T

    The new tab is visible on the the tab bar but clicking on it does not open a new tab.Neither can I open a new tab from the File drop down menu, nor the Ctrl+T method as indicated in the troubleshooting guide.

    Un-install the '''''Ask Toolbar''''' which many users have reported causing that problem.
    *http://support.mozilla.com/en-US/kb/Uninstalling+add-ons
    *http://support.mozilla.com/en-US/kb/Cannot%20uninstall%20an%20add-on
    <br />
    <br />
    '''You need to update the following.''' The Plugin version(s) shown below was/were submitted with your question and is/are out of date. You should update to avoid known security issues with the version(s) you have installed. Click on "More system info..." to the right of your question to see what was included with your question.
    *Adobe Shockwave for Director Netscape plug-in, version 11.5
    *Shockwave Flash 10.1 r102
    *Next Generation Java Plug-in 1.6.0_24 for Mozilla browsers
    #'''''Check your plugin versions''''' on either of the following links':
    #*http://www.mozilla.com/en-US/plugincheck/
    #*https://www-trunk.stage.mozilla.com/en-US/plugincheck/
    #*'''Note: plugin check page does not have information on all plugin versions'''
    #*There are plugin specific testing links available from this page:
    #**http://kb.mozillazine.org/Testing_plugins
    #'''Update Shockwave for Director'''
    #*NOTE: this is not the same as Shockwave Flash; this installs the Shockwave Player.
    #*Use Firefox to download and SAVE the installer to your hard drive from the link in the article below (Desktop is a good place so you can find it).
    #*When the download is complete, exit Firefox (File > Exit)
    #*locate and double-click in the installer you just downloaded, let the install complete.
    #*Restart Firefox and check your plugins again.
    #*'''<u>Download link and more information</u>''': http://support.mozilla.com/en-US/kb/Using+the+Shockwave+plugin+with+Firefox
    #'''Update the [[Managing the Flash plugin|Flash]] plugin''' to the latest version.
    #*Download and SAVE to your Desktop so you can find the installer later
    #*If you do not have the current version, click on the "Player Download Center" link on the "'''Download and information'''" or "'''Download Manual installers'''" below
    #*After download is complete, exit Firefox
    #*Click on the installer you just downloaded and install
    #**Windows 7 and Vista: may need to right-click the installer and choose "Run as Administrator"
    #*Start Firefox and check your version again or test the installation by going back to the download link below
    #*'''Download and information''': http://www.adobe.com/software/flash/about/
    #**Use Firefox to go to the above site to update the Firefox plugin (will also install plugin for most other browsers; except IE)
    #**Use IE to go to the above site to update the IE ActiveX
    #*'''Download Manual installers'''.
    #**http://kb2.adobe.com/cps/191/tn_19166.html#main_ManualInstaller
    #**Note separate links for:
    #***Plugin for Firefox and most other browsers
    #***ActiveX for IE
    #'''Update the [[Java]] plugin''' to the latest version.
    #*Download site: http://www.oracle.com/technetwork/java/javase/downloads/index.html (Java Platform: Download JRE)
    #**'''''Be sure to <u>un-check the Yahoo Toolbar</u> option during the install if you do not want it installed.
    #*Also see "Manual Update" in this article to update from the Java Control Panel in Windows Control Panel: http://support.mozilla.com/en-US/kb/Using+the+Java+plugin+with+Firefox#Updates
    #* Removing old versions (if needed): http://www.java.com/en/download/faq/remove_olderversions.xml
    #* Remove multiple Java Console extensions (if needed): http://kb.mozillazine.org/Firefox_:_FAQs_:_Install_Java#Multiple_Java_Console_extensions
    #*Java Test: http://www.java.com/en/download/help/testvm.xml

  • Firefox drop down disconnects when using multi-screen.

    I'm not sure if this is a new issue w/ Snow Leopard or if it's an old one. It's a new one for me.
    I opened Firefox on my laptop screen which is also connected to the 23" Apple Cinema display. I moved the browser window to the Cinema display and now the drop down boxes are redrawing on the laptop screen instead of the Cinema display. Just thought I'd report this. Can anyone else reproduce this

    I never found a solution to this but Firefox has upgraded since this question was posted and I haven't noticed this issue recurring in over 2 years.

  • Comcast email doesn't work with firefox 26. I can't get a full inbox, get to my preferences to change, drop downs need to use arrows to get to

    firefox 26 doesn't work with comcast email. won't keep me signed in; won't show whole inbox in either full or lite; won't allow me to get to preferences; drop downs only work with arrows. I could just keep going.
    Earlier this week they worked fine.

    Be sure to delete the login.comcast.net cookie, it is not near the other comcast and xfinity cookies.

  • HT4864 The Outgoing Mail Server drop down box in mail setup keeps reverting back to 'None' - anyone have any ideas why?

    Hi
    I've been having difficulties with mail on my Mac and have checked all the settings.  I have three mail accounts, 2 iClouds (different acct names) and 1 bigpond account. 
    Whenever I change the outgoing mail server drop down boxes for the iCloud accts and save my changes, I go out of it then when I go back to the iCloud accts the drop down boxes for both iCloud accounts have reverted back to 'None'. 
    Is this of any relevance?  Is it 'normal'? 
    I've tried deleting all mail accounts and adding them all again but the same thing still happens. 
    I have been on Apple Support and followed the Mail Acct setup tutorial.
    I'd appreciate any help on this matter thanks.

    Thanks for your reply Winston Churchill.
    Because I'd been having problems which had recently been resolved by AppleCare Support I decided to go through all my accounts and check their individual settings.  I found a Tutorial on Apple support for setting up or verifying email account settings and found mine were different so I changed it.
    In any event I took your advice and just went with the option of automatically setting the iCloud accounts up and I haven't had anymore problems thus far - fingers crossed.
    I do however note that my drop down box in account settings still says 'none' for the outgoing mail server and the 'use this server only' check box isn't ticked despite being ticked in the 'verify account' info on the tutorial, so hence my question to the community - did this matter and what was the difference?
    I will let sleeping dogs lie I think and will see how I go.
    Many thanks for your help.

  • Yesterday I updated logic pro and my IK Multimedia ARC system has disappeared from the plug in drop down window, how can I get it back, it appears on old files but not new ones

    yesterday I updated logic pro, I have just discovered that my IK Multimedia ARC system has disappeared from the plug in drop down window, can anyone advise how I can get it back. It seems that old logic files where it was previously loaded still have the plug in live, but on a new project file it simply isn't there to select and activate.

    Not sure about your issue. What did you update from and to? Is ARC still in the plugins/components folder?
    I'm an ARC user too. I have it plugged in to Audio Hijack Pro which is set to hijack audio from Logic. This way ARC is after logic and you don't have to remember to bypass the plugin before you bounce.

  • I accidentally deleted my "recently bookmarked" option in my drop down menu How do I get it back?

    in the tool bar there is a section marked bookmarks. In the drop-down menu there was an option "recently bookmarked" which I accidentally deleted ... How do I get it back?
    Thanks

    This link shows how to restore it - https://support.mozilla.com/kb/Restore+the+default+Smart+Bookmarks+Folders

  • Why can't my jsp use this bean??

    hi,
    i'm stuck with this problem since yesterday. hope anyone can help me sort this out. i'll try to state my problem here as clear as possible...
    i have a jsp page named call.jsp which i put in the folder
    C:\Tomcat 5.5\webapps\ROOT\mypage\
    here's the content (partially) of the call.jsp
    <%@ page import = "login.*" %>
    <jsp:useBean id="mybean" class="login.loginDB"/>and here's the content of the bean which this call.jsp is trying to call. name of the bean is loginDB.java. i put the the loginDB.java inside this folder:
    C:\Tomcat 5.5\webapps\ROOT\mypage\WEB-INF\classes\login
    then i compiled the java file using the command prompt
    C:\Tomcat 5.5\webapps\ROOT\mypage\WEB-INF\classes\login\javac loginDB.java
    and so the output is loginDB.class which obviously is placed in the folder C:\Tomcat 5.5\webapps\ROOT\mypage\WEB-INF\classes\login\
    here's the content of loginDB.java:
    package login;
    import java.sql.*;
    import java.util.*;
    public class loginDB implements java.io.Serializable {
         private String dbServer = "localhost";
         private String dbName = "toyo-SMP";
         //getter
         public String getdbServer(){
              return dbServer;
         public String getdbName(){
              return dbName;
    }so the problem is, everytime i call call.jsp, this error will come out:
    org.apache.jasper.JasperException: /SMP-toyo/logoutPekerja.jsp(85,0) The value for the useBean class attribute login.loginDB is invalid.
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)i don't know what else should i to. thanks a lot for helping.
    btw i'm using tomcat 5.5.20 with jdk 1.5

    I got it why you are getting below above error: You should have a public constructor in your bean class without any arguments. Modify your bean like this:
    package login;
    import java.sql.*;
    import java.util.*;
    public class loginDB implements java.io.Serializable {
         private String dbServer = "localhost";
         private String dbName = "toyo-SMP";
    //Constructor
         public loginDB (){
         //getter
         public String getdbServer(){
              return dbServer;
         public String getdbName(){
              return dbName;
    }

  • Why, suddenly can't I create a new tab through the "file' drop down or by using the "add a tab" button.

    The only way I can create a new tab right now is to right click on a link in the current tab and ask it to "open in new tab".

    This problem in is Firefox on your Mac?
    May users have discovered this problem is caused by Conduit add-ons, such as a Conduit plugin and/or a "Community Toolbar" extension.
    You can check for and disable extensions on the Add-ons page. Either:
    * Command+Shift+a
    * "3-bar" menu button (or Tools menu) > Add-ons
    In the left column, click Extensions. Then, if in doubt, disable.
    Often a link will appear above at least one disabled extension to restart Firefox. You can complete your work on the tab and click one of the links as the last step.
    Does that help with the "+" button? If so, could you name the specific extension that caused the problem?
    You might also check the Plugins section of the Add-ons page. You can use "Never Activate" to disable plugins that you don't ordinarily use.

  • O make the In system preferences under Sound, there is no drop-down menu for "Use audio port for."  How do I switch the port to input?

    I'm trying to use the audio input/output port to record in Garageband.  When I plug in my guitar it isn't recognized, and when I go to sound prefrences it does not give me the option to switch between input and output.  How do I switch it to input?

    For GarageBand issues post in that forum.

Maybe you are looking for