Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Declare tag methods in jsp 
 

JSP is a extended technology to the java servlet that allows to keep separate the dynamic part of your pages from the static HTML.

 

Declare tag methods in jsp

                         

JSP is a extended technology to the java servlet that allows to keep separate the dynamic part of your pages from the static HTML. In the code of web page HTML will be as it is but dynamic part is enclosed in special tag , most of which start with "<%" and end with "%>". This is known as scriptlet part of the page.

We can declare the variables and methods in scriptlet part but the scope of these members will be only in same block in which they are declared, to resolve this problem Jsp provide special type of declaration which have scope throughout the page. This special type of declaration uses tags given below...

Declare variables : <%! int number; %>

Declare methods : <%!  void display() { out.println("My JSP Page");  }  %>

Before run this jsp code create a new directory named "user" in the tomcat-6.0.16/webapps and paste WEB-INF directory in same.

declaration_tag_method.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%!
  private String getName() {
    return "Mahendra Singh";
  }
  private String phone() {
    return "9990254913";
  }
  private String getCity() {
      return "Delhi";
  }
%>
<html>
    <head>
        <TITLE>Example of Declaration Tag - Methods</TITLE>
	</HEAD>
    <BODY bgcolor="#6E6E6E">
	   <font size="+3" color="#F2F2F2">
         Information about <%= getName() %>...<br>
         Contact Number : <%= phone()%><br>
         City : <%= getCity() %>
	   </font>
    </body>
</html>

Save this code as a .jsp file named "declaration_tag_method.jsp" in the directory Tomcat-6.0.16/webapps/user/ and you can run this jsp page with following url in address bar of the browser http://localhost:8080/user/declaration_tag_method.jsp

Download Source Code

                         

» View all related tutorials
Related Tags: java c apache script import model io method user sed column ip port columns int line this package tar oo

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.