STK
asked on
JSP bean and drop down boxes
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.
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.
ASKER
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("S ELECT user_name FROM member WHERE UPPER(user_name) = ? AND UPPER(password1) = ?");
sql.setString(1, request.getParameter("user name"));
sql.setString(2, request.getParameter("pass word"));
results = sql.executeQuery();
while(results.next())
{
if(! doneheading)
{
out.println("<table border=2>");
doneheading = true;
}
mybean.setString(results.g etString(" user_name" ));
the error that tomcat is giving me is that the period after mybean is "cannot resolve symbol"
sql = dbconn.prepareStatement("S
sql.setString(1, request.getParameter("user
sql.setString(2, request.getParameter("pass
results = sql.executeQuery();
while(results.next())
{
if(! doneheading)
{
out.println("<table border=2>");
doneheading = true;
}
mybean.setString(results.g
do you have setString method in your bean? what property does you bean have? maybe something like mybea.setUserName() ?
ASKER
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.memberhandle r" %>
<jsp:useBean id="mybean" scope="application"
class="hello.memberhandler " />
<jsp:setProperty name="mybean" property="username" />
private String username
public void setUsername( String name ) {
username = name;
}
<%@ page import="hello.memberhandle
<jsp:useBean id="mybean" scope="application"
class="hello.memberhandler
<jsp:setProperty name="mybean" property="username" />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>