?
Solved

JSP bean and drop down boxes

Posted on 2003-03-27
5
Medium Priority
?
222 Views
Last Modified: 2010-07-27
First...I'm trying to store a data into a bean...The two text boxes that are used are called lets say text1 and text2 but i don't want to store these in the bean. I need text1 and text2 to query the database which i want to store in the bean.

Please supply some sample code of how i would store the querying piece of data in my bean?

Second...I would like to use drop down boxes for some date fields in my JSP docs but i don't know how to do them. I want to query the database when the focus is on the drop down box and query for most of the recent dates in order for the user to pick one of them. How do i query the data base and user drop down boxes at the same time. I can't seem to visulize it and example would help also.

0
Comment
Question by:STK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 8221154
Q1, not quite understand what you mean, do you mean use text1 and 2 as condition parameter to query database and get the value back? if this is the case, then:

PreparedStatement ps = conn.prepareStatement( "select * from table1 where column1=? and column2=? );
ps.setString( 1, request.getParameter( "text1" );
ps.setString( 2, request.getParameter( "text2" );
ResultSet rs = ps.executeQuery();
if( rs.next() ) {
   bean.setXXX( rs.getString( "xxxx" );
   ....
}

Q2, http is a request/response model. you can access database when user click the drop down button. you can only pre-polulate it. e.g.:
<% ResultSet rs = ..... %>
<select name="xxx">
<% while( rs.next() ) { %>
   <option><%=rs.getString( "column1" )%></option>
<% } %>
</select>


0
 

Author Comment

by:STK
ID: 8222085
Trying your solution to Q1 i wrote the following code but i don't think i'm quite right. What is wrong?

the error that tomcat is giving me is that the period after mybean is "cannot resolve symbol"


sql = dbconn.prepareStatement("SELECT user_name FROM member WHERE UPPER(user_name) = ? AND UPPER(password1) = ?");
           
            sql.setString(1, request.getParameter("username"));
            sql.setString(2, request.getParameter("password"));
         
            results = sql.executeQuery();
           
            while(results.next())
            {
                 if(! doneheading)
                 {
                      out.println("<table border=2>");
                      doneheading = true;
                     
                 }
               
                 mybean.setString(results.getString("user_name"));

0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8222105
do you have setString method in your bean? what property does you bean have? maybe something like mybea.setUserName() ?
0
 

Author Comment

by:STK
ID: 8222221
all i have is what is above and this. Yes i do have a set string in my bean

private String username

public void setUsername( String name ) {
        username = name;
    }

<%@ page import="hello.memberhandler" %>

<jsp:useBean id="mybean" scope="application"
          class="hello.memberhandler" />
<jsp:setProperty name="mybean" property="username" />
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 80 total points
ID: 8222240
NO, you don't have setString method, you have setUsername method!
use this:
mybean.setUsername(results.getString("user_name"));
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question