473,471 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Not able to retrieve the data from bean

5 New Member
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
0 1313

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

Similar topics

3
by: Jose Munoz | last post by:
Hi all, I want to share some data for all my applications (servlets and jsps). For this i am using a JSP to set the variables with scope=application. When i get this data from some JSP all is o.k,...
0
by: Xiest | last post by:
Hi all, Am trying to add a recorset to a java bean and then add the bean to a Collection, but it seen that the Bean properties are pointing to the recordset so every time I move the recordset to...
3
by: Miles Davenport | last post by:
I have the following code (please see base of email) which displays text from a properties file ok. I have changed the properties file so the contents are different, but cannot get the new...
0
by: Borek | last post by:
In my project I have to access in one business method of session bean usually more then 10 CMP Beans. I would like to have some utils classes, which could get me right instance of CMP or create...
3
by: Dave | last post by:
I think this is a simple struts question.... I want to display information on a page in a static way. That is, not as part of text elements. I can't find an appropriate struts tag to use. ...
1
by: hostel | last post by:
HTML PAGE <html> <body> <form action="second.jsp" method="get"> YOur name <input type=text name="name"> <input type=submit > </form> </body> </html>
9
by: stack | last post by:
Hi all, I am creating a web app using JSP. I have a bean with some variables whose values are set by the user by using a form in a jsp (method is post). When the user enters those values these are...
12
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
9
by: gavy7210 | last post by:
hello friends i am new to struts. i want to add the user information in the database and then display it back to him. i am using struts 1.2,Eclipse Platform Version: 3.4.2,mySql 5.0.1,jdk...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.