Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Call JavaBean methods from JSP

Call JavaBean methods from JSP 2.0 pages

Tutorial Details:

Develop custom tags with dynamic attributes
he new JavaServer Pages (JSP) version incorporates the expression language (EL) introduced by the JSP Standard Tag Library (JSTL) to let Web designers produce scriptless JSP pages that don't contain Java code. Since JSP 2.0 provides backward compatibility to JSP 1.x, you may still include Java snippets in your pages, but tag handlers and JavaBean components are much better places for Java-based functionality.

JSP 2.0 provides new features for tag handlers such as dynamic attributes, the Simple Invocation Protocol, and .tag files. You still use the old JSP 1.0 standard actions for creating JavaBean instances and setting their properties, but now you can access bean properties, request parameters, and JSP attributes/variables with the new expression language.
All those JSP technology improvements let you achieve the goal of separating the JSP/HTML markup from the Java code. One thing is missing, however. JSP 2.0 has no syntax for calling a public nonstatic JavaBean method from a scriptless JSP page. This article solves that issue by providing a JSP 2.0 simple tag with dynamic attributes.

Note: You can download this article's source code from Resources .
Expression language needed
Suppose you have a java.util.List instance you must present as an HTML list. Here is a quick solution based on JSP 1.x:


    <%
    Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
    Object elem = iterator.next();
    if (elem == null)
    elem = "";
    %>
  • <%= elem %>

  • <%
    }
    %>


Existing JSP-based Web applications consist of Java code mixed with HTML markup like the above code fragment.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Call JavaBean methods from JSP

View Tutorial:
Call JavaBean methods from JSP

Related Tutorials:

Bean Markup Language, Part 1 - JavaWorld August 1999
Bean Markup Language, Part 1 - JavaWorld August 1999
 
Using XML and JSP together - JavaWorld March 2000
Using XML and JSP together - JavaWorld March 2000
 
Advanced form processing using JSP
This article examines the processing of a user registration form using JSP and JavaBeans while implementing the Memento design pattern.
 
Encapsulate reusable functionality in JSP
This tutorial shows you how you can encapsulate the resuable functionality in JSP pages.
 
Which JSP book serves up the best lesson?
Which JSP bookAs for Web servers/databases, just mentioning a server in the book is not sufficient to be listed here.
 
Process JSPs effectively with JavaBeans
This articles shows your how you can process JSPs effectively with JavaBeans
 
An open alternative to JSP - The faults of JSP So what's wrong with JSP?
How the template-based, open source API FreeMarker trumps JSP
 
Get disconnected with CachedRowSet , This allows for ResultSet s to be serialized, sent to remote clients, updated
The new J2EE RowSet implementation provides updateable disconnected ResultSets in your JSPs
 
Superior app management with JMX - JavaWorld June
Integrate JMX, a reusable configuration framework, with your JSPs
 
Facilitate form
Facilitate form processing with the Form Processing API
 
JSP best practices
Follow these tips for reusable and easily maintainable JavaServer Pages
 
Generate JavaBean classes dynamically with XSLT
Generate JavaBean classes dynamically with XSLT
 
Boost Struts with
Boost Struts with XSLT and XML
 
Call JavaBean methods from JSP
Call JavaBean methods from JSP 2.0 pages
 
JSP Tutorial
Adding dynamic content via expressionsAs we saw in the previous section, any HTML file can be turned into a JSP file by changing its extension to .jsp. Of course, what makes JSP useful is the ability to embed Java. Put the following text in a file wit
 
Compare JavaServer Pages: Tag Libraries vs. JavaBeans
Java provides developers with JavaServer Pages (JSPs) and Servlets as a superior alternative to traditional CGI programs. The architecture of JSPs provide support for a logical and physical separation between the HTML page designers and the component deve
 
J2EE pathfinder: Implement JSP custom tags in five easy steps
JSP custom tags provide a standardized mechanism for separating presentation and business logic in a dynamic Web page, allowing page designers to focus on presentation while application developers code the back end. In this installment of J2EE pathfinder,
 
Encapsulate reusable functionality in JSP tags
JavaServer Pages (JSP) are a great mechanism for delivering dynamic Web-based content. JSP provides a set of predefined tags, but you can also define your own tag extensions that encapsulate common functionality.
 
Calling JavaBeans from a JSP Page
We will be using this SimpleBean class in this tutorial, so if you haven't read above article then I suggest you do it now.
 
JSP Architecture
JSP Architecture JSP ARCHITECTURE J PS pages are high level extension of servlet and it enable the developers to embed java code in html pages. JSP files are finally compiled into a servlet by the JSP engine. Compiled servlet is used by the engine
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.