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.
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.
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.
An IDE is no substitute for an Intelligent Developer.