Basic JSP Sample : Passing Parameters

Previous Contents Next

Contents

Purpose

Accept user input and pass it as a parameter.

Remarks

This demo shows how a JSP can access the HTTP request object. This object is named request and is available implicitly in any JSP. It provides a getParameter method for retrieving parameter values by name.

The JSP syntax defines two levels of tags. The basic JSP tags (prefixed with <%) are sufficient for writing any JSP page. However, to make it easier to encapsulate a page's business logic, the JSP architects defined additional tags (prefixed with <jsp:) for declaring and initializing JavaBeans. (The <jsp: tag set was further expanded to simplify other common page operations such as including or forwarding a request.) Such tags enable a clean separation of application logic from presentation formatting. For example, the tag <jsp:useBean> provides access to JavaBeans without requiring the page designer to know anything about Java.

JSP also supports custom tag sets. For example, OC4J JSP provides extended functionality through custom tags and custom JavaBeans which are portable to other JSP environments. These extensions include the OC4J JSP Markup Language (JML) custom tag library, which reduces the level of Java proficiency required for JSP development. This example uses JML tags to execute certain blocks of code only when certain conditions are met.

Code from HelloUser.jsp

<%
// Get the value of 'whichUser' Parameter from the request object
String l_whichUser = request.getParameter("whichUser");
if (l_whichUser != null) {
// If the parameter has a value, display it
if (!l_whichUser.equals("")) {
%>
<BR><BR>
<TABLE BORDER=1 BGCOLOR=BLACK>
<TD><FONT COLOR=RED SIZE=4><B>
<% out.println("Hello "+ l_whichUser+"!"); %>
</TD>
</TABLE>
<% } %>

 

Code from HelloUserUsingBean.jsp

<jsp:useBean   class="HelloUserBean"  id="one"  scope="page" >
<% // Get the value of 'whichUser' Parameter from the request object
String l_whichUser = request.getParameter("whichUser");
if (l_whichUser != null) {
// If the parameter has a value, display it
if (!l_whichUser.equals("")) {
%>
<TABLE BORDER=1 BGCOLOR=BLACK>
<TD><FONT COLOR=RED SIZE=4><B>
<% one.setMessage(l_whichUser); %>
<%= one.getMessage() %>
</TD>
<% } %>

 

Code from HelloUserUsingTags.jsp

<jml:if condition = "<%= l_message.equals(\"Hello !\") %>" >
<TABLE BORDER=1 BGCOLOR=BLACK>
<TD><FONT COLOR=RED SIZE=4>
<jml:print eval = "Please Enter the User Name!" />
</TD>
</TABLE>
</jml:if>
<jml:if condition = "<%= !l_message.equals(\"Hello !\") %>" >
<TABLE BORDER=1 BGCOLOR=BLACK>
<TD><FONT COLOR=RED SIZE=4>
<jml:print eval = "<%= HelloUserBean.getMessage() %>" />
</TD>
</TABLE>
</jml:if>

 

Source Code Listings


Previous Contents Next
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy