• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic