Results 1 to 2 of 2
  1. #1
    sathya_k_83 is offline Member
    Join Date
    Nov 2007
    Posts
    3
    Rep Power
    0

    Default how to populate html:select with values from database

    i am developing a struts project.

    The employee Login table has
    1)EmpId , EmpName , RoleId.
    i want to read the roleid from the RoleTable(DB)
    and populate in the employee Login Form

    can any one tell me how to populate the from Data base

  2. #2
    JavaThinker is offline Member
    Join Date
    Nov 2007
    Posts
    3
    Rep Power
    0

    Default Use Custom Tag Libraries

    Hi,

    This could be achieved using custom tag libraries.

    It is a 3 step process:-

    1. Prepare a TLD file, with the details of the tag you wish to create. For example, name "roleselect" and tagclass as "myapps.trial.RoleSelect".
    2. Implement the tagclass "myapps.trial.RoleSelect" extending TagSupport. You will need to implement 2 methods - doStartTag() and doEndTag(). In these methods, you may query the database for the values of roleid and use these to prepare the HTML code for Select. Finally, out put this HTML code to a JSPWriter.
    3. In you JSP file, include the tag library(TLD file) by specifying the TLD file path in your taglib attribute like this:
    <%@ taglib url=".. GIVE PATH OF YOUR TLD FILE .." prefix="my" %>
    Then, the roleid select dropdown can be obtained by simple putting <my:roleselect /> at the appropriate place in the JSP file.

    I hope that gives you some idea of how you could get started. You may need to do some more study JSP custome tags.

    Regards,
    JavaThinker

Similar Threads

  1. getting values from database in dropdown
    By aa74 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-21-2008, 11:00 PM
  2. Replies: 4
    Last Post: 04-15-2008, 02:04 PM
  3. Displaying a Java List in Html:select tag
    By ramitmehra123 in forum New To Java
    Replies: 0
    Last Post: 02-07-2008, 06:48 AM
  4. Getting HTML form values in Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-17-2007, 09:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •