This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 15950
    
  19

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
 
Similar Threads
diff b/w doGet() and servlet()
database interaction in jsps
Interaction of Java with Mainframes
what is coupling
jsp/sql server connection problem