By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,843 Members | 864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,843 IT Pros & Developers. It's quick & easy.

Not able to retrieve the data from bean

P: 5
What iam exactly trying to do is..saving the resultset in a bean.....and calling the bean in a servlet and forwarding it to jsp by setting the bean in the request scope;
Now i have only one record in the db;
But still iam getting the servlet as wellas jsp with
no 0
name null;

Here is the code:


public class dbbean {
private int number;
private String name;

public void setNumber(int number)

public void setName(String name)

public int getNumber()
return number;

public String getName()
return name;

public class Getdata extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
PrintWriter out=res.getWriter();
dbbean db1=new dbbean();

//call setters to initialize bean
req.setAttribute("dbBean", db1);
int no=db1.getNumber();
String name=db1.getName();
out.println("<h1>Hi </h1>");
out.println("number:"+ no);
out.println("Name:" + name);
// ServletContext sc = getServletContext();
// RequestDispatcher rd = sc.getRequestDispatcher("/disp.jsp");
// rd.forward(req, res);


<title>Data from xml</title>
<%@ page import="java.sql.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="javax.servlet.jsp.*" %>
<%@ page language="java" import="samples.dbbean.*" %>

<jsp:useBean id="dbBean" type="samples.dbbean" scope="request"/>
Number : <input type="text" name="text1" value=<%=dbBean.getNumber() %> /><br>
Name: <input type="text" name="text2" value=<%=dbBean.getName() %> />


Thanks again
Nov 16 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.