aspose file tools*
The moose likes Servlets and the fly likes Newbie-general question: interaction b/w jsp, beans, and servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Newbie-general question: interaction b/w jsp, beans, and servlets" Watch "Newbie-general question: interaction b/w jsp, beans, and servlets" New topic
Author

Newbie-general question: interaction b/w jsp, beans, and servlets

Andrew C
Greenhorn

Joined: Jul 31, 2001
Posts: 1
I'm new to Java and its related technologies, and I've been looking through a couple of books, but no books seem to address a basic question I have. I know jsp are used to seperate the presentation from the business logic, but when should you write a function(method) in a bean or servlet? I know bean methods can only be public, but if I meet this requirement then where should I put my code-in a bean or servlet? And what is the interaction b/w a jsp, bean and servlet if they all exist in an environment.
Shuaib Gill
Ranch Hand

Joined: May 29, 2001
Posts: 62
Use a JSP to call a servlet through a forms action method...
<form action="myserver/someServlet" method=get>
In the servlet, make a object of a java bean.
SomeBean obj=new SomeBean();
// the use the beans setXXX()
obj.setSomeval();
In the jsp, use the useBean attribute and the beans getXXX() to retrieve the same data.


programmer77
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

JSPs and servlets are functionally equivalent for most purposes - the difference is that a servler is pure code whereas a JSP is usually compiled to code (a type of servlet, generally) before the code is compiled to make a class. The JSP is easier to work with as a view - for example, in HTML editors.
Beans can be data-only, function-only or (though not generally recommended) mixed.
As to where you put the business logic - it's up to you. In simple cases, you can dispense with beans entirely. In cases where you want reusable code, or want to make the system more maintainable, you'd usually want to break functionality into more components.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie-general question: interaction b/w jsp, beans, and servlets