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:

import java.io.Serializable;

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

public void setNumber(int number)
{
this.number=number;
}

public void setName(String name)
{
this.name=name;
}

public int getNumber()
{
return number;
}

public String getName()
{
return name;
}
}

servlet:
public class Getdata extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
res.setContentType("text/html");
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("<html");
out.println("<body");
out.println("<h1>Hi </h1>");
out.println("number:"+ no);
out.println("<br>");
out.println("Name:" + name);
out.println("</body");
out.println("</html>");
// ServletContext sc = getServletContext();
// RequestDispatcher rd = sc.getRequestDispatcher("/disp.jsp");
// rd.forward(req, res);
}

}


Jsp:
<html>
<head>
<title>Data from xml</title>
</head>
<body>
<%@ 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() %> />
</

</body>
</html>


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.