?
Solved

JSP bean info needed

Posted on 2003-03-28
7
Medium Priority
?
674 Views
Last Modified: 2012-05-04
I have a String stored in my bean and want to get the String from the bean and place it into mySQL database from a JSP page. i want to use the string to use as a search parameter in the select statement. Can this be done and if so...HOW?

Also how do you clear the contents of a bean?
0
Comment
Question by:sredmusarm
[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
7 Comments
 
LVL 11

Expert Comment

by:fargo
ID: 8228326
Hii,
You didn't post any code...well, what i can guess is..if u have set and get methods in ur java class...then call the method in ur jsp...and used it in the query...

say...

String searchstring = instance.getSome();

then in query...

select * from ur_table where something like "'+ searchstring+'%";

then u can use set method to reset the value...

instance.setSome("");

if u have any problems, then try to post ur code..may be we can help u better then.

happy working
fargo
0
 

Author Comment

by:sredmusarm
ID: 8231670
I don't understand what you mean above...please try and explain more
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 8233572
Try example below:

Example of bean:

package app;

import java.util.*;

public class Submission extends Object
{

private String email = "";

public void setEmail(String value)
     {
          this.email = value;
     }
     public String getEmail()
     {
          return email;
    }
}

To get the value, use:


In your JSP:

<%@page import="app.*"%>
<jsp:useBean id="sub"       scope="session"                  class="app.Submission"/>

<jsp:setProperty name="sub" property="email"                  param="email"/>


<%=sub.getEmail()%>

Where the form is posted value of field "email".

Hope this helps
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Ryan Chong
ID: 8233577
For more information, you can refer to http://www.jspin.com/ and http://www.jspinsider.com/ for java bean and database connection.

cheers
0
 

Author Comment

by:sredmusarm
ID: 8234300
well i have changed it up but i'm not getting the results needed. When i do the query in the database i get the results but i'm not getting anything coming up on the screen...anyone know why? The error is near the While loop

 String fname, lname;
            boolean doneheading = false;
           
           
            dbconn = DriverManager.getConnection("jdbc:mysql://localhost/nutrition","saundersk","kevin");
            sql = dbconn.prepareStatement("SELECT first_name, last_name FROM member_info WHERE username = ?");
           
            sql.setString(1, request.getParameter(mybean.getUsername()));
       
            results = sql.executeQuery();
     
            while(results.next())
            {
                 out.println("1");
                 if(! doneheading)
                 {
                     
                      doneheading = true;
                     
                 }
                fname = results.getString("first_name");
                lname = results.getString("last_name");
                 out.println(fname);
                 out.println(lname);
                 
            }
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 80 total points
ID: 8235967
>>sql.setString(1, request.getParameter(mybean.getUsername()));

This line looks weird, try:

sql.setString(1, request.getParameter("Username");

or
     
sql.setString(1, mybean.getUsername());
0
 
LVL 4

Expert Comment

by:Binary1
ID: 8240504
This line is combining two different things, one is the request parameters and the second is the bean value.

sql.setString(1, request.getParameter(mybean.getUsername()));


To set the parameter using the bean use

sql.setString(1,mybean.getUsername());




0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

771 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