Free WebSchools.com

Google




Blog ForumsLive chat WebhostingLink TO UsResources


HOME

Java Server Pages

JSP Introduction
JSP Syntax
JSP Expression
JSP Declaration
JSP Comments
JSP Directives
JSP Actions
JavaBeans
JSP Sessions
JSP And HTML Forms
JSP With XML
JSP Aand Servlets


JSP Actions



Actions provide an abstraction that can be used to easily encapsulate common tasks. They are specific tags that affect the runtime of the JSP and the response sent back to the client. They normally create or act on objects. The standard action types are
  • <jsp:param>
  • <jsp:include>
  • <jsp:forward>
  • <jsp:plugin>
  • <jsp:useBean>
  • <jsp:setProperty>
  • <jsp:getProperty>

now we discuss these one by one

JSP param



<jsp:param>
This action is used to provide other tags additional information in the form of the values. It is used in jsp:include, jsp:forward and jsp:plugin action elements. In doing so the included or forwarded page will see the request object, with original parameters augmented with the new values that take precedence over existing values. The <jsp:param> clause allows you to pass one or more name/values pairs as parameters to an included file. It syntax is

<jsp:param name=”name” values=”value />



JSP include

This action allows a static or dynamic resource to be included in the JSP at request time. An included page has access only to the jspWriter object; it cannot set headers or cookies. Its syntax is <jsp:include page=”{relative URL|<%= expression %>}” flush=”true” />

Now let us try the example of <jsp:param> and <jsp:include>

Action.jsp

<html>
<head><title>student information</title></head>
<body>
<table width=”50%” >
<tr><td>
<jsp:include page=”header.jsp” flush=”false”>
<jsp:param name=”stname” value=”hari” />
<jsp:param name=”stno”  value=”2” />
</jsp:include>
</td></tr></table></body></html>

header.jsp

<% out.println(student name : “+request.getParameter(“stname”)+”<br>”);
out.println(“student rollnumber  :”request.getParameter(“stno”)+”<br>”);
%>

JSP Forward




This action forwards a client request to an HTML file, JSP file or servlet for processing. it syntax is

<jsp:forward page=”{relativeURL | <%= expression %>” />

The <jsp:forward> elements forwards the request object containing the client request information form one JSP file to another file. The target file can be an HTML file, another JSP file, or a servlet, as long as it is in the same application context as the forwarding JSP file.

Example for jsp:forward

fwd.html

<html>
<body bgcolor=#34345>
<form method="post"  action="Forward.jsp">
<input type="text"  name=option  value="">
<input type=submit value="Click Me">
</form>
</body>
</html>


Forward.jsp
<html>
<title> Using Forward Tag </title>
<body>
<%

if( request.getParameter("option").equals("1"))
{  %>
<jsp:forward   page="one.jsp"/>
<%}
else
{ %>
<jsp:forward page="two.jsp"/>
<%
}
%>
</body>


one.jsp

<html>
<body bgcolor="pink">
<h1>This is pink Page</h1>
</body>
</html>


two.jsp



<html>
<body bgcolor="lightgreen">
<h1>This is green Page</h1>
</body>
</html>


JSP Plugin



<jsp:plugin>

This action executes an applet or Bean and if necessary,downloads a java plug-in to execute it. It ssyntax is

<jsp:plugin type=”bean|applet” code=”classFileName” codebase=”classFileDirectoryName”

[ name=”instanceName” ]
[ align=”bottom|top|middle|left|right” ]
[ height=”dispalyPixels” ]
[ width=”dispalyPixels” ]
[ hspace=”leftRightPixels” ]
[vspace=”topBottomPixels” ]
[ nsppluginurl=”URLToPlugin” ] >


the <jsp:plugin> elements plays or displays an object(an applet or Bean) in the client web browser, using Java plug-in that is built into the browser or downloaded form a specified URL. When JSP file is translated and compiled and java back an HTML response to the client, the element is replaced by either an or element, according to browser version. The attributes to the <jsp:plugin> element specify weather the object is a Bean or an applet

Here is the simple example of <jsp:plugin>

App.java

Import  java.awt.*;
Import java.awt.event.*;
Import java.applet. Applet;
public class App extends Applet
{
TextField txtname;
TextField txtage;
Label lname,lage;
Button bsubmit;
Panel pcenter=new panel();
Panel pNorth=new Panel();
Int sn;
private void setgui()
{
pcenter.setLayout(new GridLayout(3,2));
lname=new  Label(“name”);
lage=new Label(“age”);
txtname=new TextField(“”);
txtage=new TextField(“”);
pCenter.add(txtname);
pCenter.add(lname);
pCenter.add(txtage);
pCenter.add(lage);
bsubmit=new Button(“submit”);
p.North(bsubmit);
add(pCenter);
setsize(400,150);
setVisible(true);
}
public void init()
{
setgui()
}
}


Appletjsp.jsp

<html>
<head><title> calling jsp throught applet</title></head>
<jsp:plugin type=”applet” code=”App” width=400 height=200>
</jsp:plugin>
</body>
</html>

JSP set and get Property



<jsp:setProperty> This action is used in conjunction with used Bean to set the value of attribute of the bean. These properties can be set at earlier.

Request time form parameters in the request object

Request time form an evaluated expression

Form a specified string (hard coding)

It syntax is < jsp:setProperty name=”beanname” propertyDetails /> <jsp:getProperty> This a ction is complimentry to the setProperty action. It is also used in conjection with usebean to retrive the value of attributes of the bean. These values are converted to a string and printed to the output stream,

its syntax is <jsp:setProperty name=”beanname” property=”propertyname” />

ASP Free - Your Source For ASP Source Code and More... ASP Free
Powered By ASP Free
Dev Shed - The Open Source Web Development Site Dev Shed
Powered By Dev Shed
Dev Articles - Your Multi-Platform Development Source Dev Articles
FORUMS
Powered By Dev Articles
SEO Chat - Search Engine Optimization SEO Chat
Powered By SEO Chat