Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet servlet javabean
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rekha
servlet javabean
1 Answer(s)      4 years and 9 months ago
Posted in : JSP-Servlet


how to use a java bean in servelts .plese give me one example program using servelt mvc concept.

Advertisement
View Answers

January 4, 2010 at 2:16 PM


Hi Friend,

Try the following code:

1)Person.java:
public class Person {
private String name;
private String email;
private long phoneNo;
public Person() {
setName("Tom Hawk");
setEmail("tom.hawk@gmail.com");
setPhoneNo(1213);
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setPhoneNo(long phoneNo) {
this.phoneNo = phoneNo;
}
public long getPhoneNo() {
return phoneNo;
}

}

2)BeanInServlet.java:

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class BeanInServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
Person p = new Person();
p.setName("Sam Dalton");
p.setEmail("sam2222@gmail.com");
p.setPhoneNo(1111111111);
req.setAttribute("person", p);
RequestDispatcher rd = req.getRequestDispatcher("/jsp/beandata.jsp");
rd.forward(req, res);
}
}

3)beandata.jsp:

<html>
<body>
<table>
<tr><td>Name is:</td><td>${person.name}</td></tr>
<tr><td>Email is:</td><td>${person.email}</td></tr>
<tr><td>PhoneNo is:</td><td>${person.phoneNo}</td></tr>
</table>
</body>
</html>

4)web.xml:

<servlet>
<servlet-name>BeanInServlet</servlet-name>
<servlet-class>BeanInServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BeanInServlet</servlet-name>
<url-pattern>/BeanInServlet</url-pattern>
</servlet-mapping>

Thanks


Related Tutorials/Questions & Answers:
servlet javabean - JSP-Servlet
servlet javabean  how to use a java bean in servelts .plese give me one example program using servelt mvc concept.  Hi Friend, Try the following code: 1)Person.java: public class Person { private String name
javabean
of JavaBean which would enable him/her to perform the task in a hidden manner. How
Advertisements
Problem insert data into database using servlet n javabean - Java Beginners
to solve it.. i really new in jsp+servlet+javabean,dont really unnderstand 1)my...Problem insert data into database using servlet n javabean  I created a servlet for registration proses I got a problem compiling my servlet
javabean in jsp
javabean in jsp  hi.. how to get the table values in jsp using javabean.????? that means i have a html prg that accepts table name and javabean prg to set the values and how to write jsp prog to get the vaues and display
Servlet
Servlet  What is Servlet
Servlet
Servlet  how to navigate one servlet page to another servlet page
servlet
servlet  is there any way to include pdf's in servlet
servlet
servlet  How many times the servlet is accessed
servlet
servlet  what are the methods and interfaces in the servlet api ?   Servlet Tutorials
servlet
servlet  how to interact with a servlet from a swing program
servlet
servlet  what are the all necessary configuration to run a servlet
servlet
servlet  i want to create a login page with servlet using database mysql? only in servlet not in jsp plzz help me out
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
Servlet
override Service method in the servlet when you extend GenericServlet to create servlet as it is mandatory to override it. But, when you extend HttpServlet to create a servlet then you can't override service method as there is a need to override
servlet
of the Servlet API. It contains the classes necessary for a standard, protocol-independent servlet. Every servlet must implement the Servlet interface in one
servlet
servlet  can i stoar record in variable which selected from table in servlet
servlet
servlet  dear sir servlet and html not run on eclips plz help me
servlet
servlet  how to create a login form using servlet using submit,edit delete button
servlet
servlet  i want a program for counting the no of times the servlet has been invoked
Servlet
Servlet  What must be implemented by all Servlets?    The Servlet Interface must be implemented by all servlets
Servlet
Servlet  I want to know the steps to write a simple servlet program... .   Hello Friend, Follow these steps: Put servlet-api.jar inside the lib folder of apache tomcat. 1)create a servlet. import java.io.*; import
Servlet
Servlet  Can a user defined function be included in a servlet? I need information regarding servlet syntax and not JSP.   Yes, you can create user defined function in Servlets. Have a look at the following link: http
servlet
servlet  I want the full coding for uploading a file in local drive D usin jsp,java class and servlet... help me thanks in advance....   ... and servlet please and thanks in advance
servlet
servlet  how to read a file from different folder using filereader in servlet   Hello Friend, Please visit the following link: http://www.roseindia.net/servlets/servlet-read-file.shtml Here you will get an useful
servlet
servlet  i want to use servlet application on my web page then what should i do. I have already webspace.   Hi Friend, Please visit the following link: Servlet Tutorials Thanks
Servlet
Servlet   Why is Servlet so popular?   Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web
Servlet
Servlet  Hi, Can any one please expalin me below topics SERVLET ENGINE 2.WHY SUPER.INIT(); Thanks alot in advance!! Regards: Akash
servlet
servlet  I want a fully readymade project on online voting system with code in java servlet and database backend as msaccess.can u plz send me as soon as possible
 

 

 

DMCA.com