QuestionsAnswered.net
What's Your Question?

How Does HTML Code Work?
HTML is to a website what a solid foundation is to a house. Without HTML code, web developers wouldn’t have anything to build on. In other words, you wouldn’t be able to read this article without proper HTML code. Learn more about how this important language works.
What Is HTML?
HTML stands for hypertext markup language, and it’s used to lay out the basic structure of a website. You can build a simple website with HTML alone, including different font sizes and types, paragraphs, photos, background colors and other basic features. If you want to make your site look modern and nicely organized, though, you’ll need to learn additional languages like CSS and JavaScript.
The Basics of How HTML Works
Writing HTML code is basically like writing instructions for a web browser on how to display a website. For example, if you write HTML background color code specifying that your site should have a blue background, browsers read the code you’ve written and follow those instructions. The actual processes behind this are complicated and involve the transfer of data through the internet. If you’re interested in designing your own websites without using templates, though, it’s not so important to understand the technical specifics of how websites are rendered in a browser. It’s enough to know that HTML is an important part of this process, and that you need to have a good HTML structure in place if you want to build a functional, attractive website.
Understanding HTML Code
HTML is often taught as an introductory coding language because it’s ultimately pretty simple. To write HTML code, all you have to do is understand the proper syntax for communicating with a computer. You’ll also need to know the right instructions to include. These instructions are known as elements. Elements consist of tags and content. There are two tags, opening and closing, that must always bookend your content. The content between these tags is what you want to display on your site, and consist of text you write, hyperlinks to other websites, links to photos and more. If you fail to use the right symbols and characters in your opening and closing tags, your HTML will not work properly. If you do use the right tags, only the content will display on a web browser.
HTML Essentials
This is content for HTML code.
Learning HTML
HTML is an important building block for a website, but the good news is that it really isn’t that complicated to learn. There are a lot of free online resources available for those who want to dig in and learn how to use HTML to build websites, and that means not only that you’ll have guidance getting started but also that you’ll have plenty of resources to turn to for information as you learn on your own.
MORE FROM QUESTIONSANSWERED.NET

How to write HTML code faster
Speed up your HTML and CSS workflow with Emmet and Pug.

Modern websites require lots of HTML code. Complex layouts with multiple different views and states can be difficult to create with just a simple text editor. Thankfully, there are a host of HTML generation tools out there to work with. Here we take a quick look at two of the more popular tools, Emmet and Pug.
However, you still need to know your HTML to use both of these powerful time-saving tools. So, before you dive in make sure you're using the popular semantic HTML tags the right way. Also see our guide to using a HTML boilerplate .
Want to swerve the code? Try these website builders . Or for extra help along the way, choose a web hosting service with tech support.
Generate HTML on the fly
When writing large amounts of HTML in one go, writing each tag out by hand can become very tedious, very quickly. For example, when writing out a list of links, we need to make sure that the <ul>, <li> and <a> tags all open and close in the right place. Otherwise the links may not work and the whole page layout will go completely haywire.
How to use Emmet
To make sure you reduce the chances of this happening you can employ the talents of Emmet (opens in new tab) . This is a tool that will save you lots of typing and will greatly improve your HTML & CSS workflow. Emmet allows you to create elements by typing out a CSS-like selector. It will then parse and expand that element into regular HTML. Below is the original element created in Emmet.
Emmet will detect this element, parse it and then transform the element into standard HTML as shown below. A quick look at the Emmet element suggests that <li> is multiplied by ( *3 ) and each <li> instance will be called Chapter followed by the appropriate number (up to 3).
Note how many characters the Emmet element contains and how many the standard HTML contains. Even this small snippet of code demonstrates how much time can be saved by using the Emmet shorthand.
Emmet is also aware of context. For example, if we are editing a <table> it is likely we will want some <tr> (these are rows) elements to fill it. All we would need to do is specify how many we need.
This is just a quick example of what Emmet can do, but there are plenty more configuration options available. These include CSS editing, BEM (Block Element Modifier) class creation and there is even a Lorem Ipsum generator.
It's also worth noting that most code editors either have Emmet built in or support it through plugins. You can find out more about this on the Emmet Documentation (opens in new tab) page.
Use Pug for dynamic content
While Emmet is ideal for static content, what happens if content needs to be more dynamic? For example, we may need to generate personalised homepages, complex order tables or repeat common blocks of HTML. This is all possible in JavaScript, but by pre-rendering this content we can get an added speed boost without relying on the user’s browser. Remember if you've got a media-heavy page, you'll want to back it up with reliable cloud storage .
Step forward Pug. This is a templating tool for HTML. You can write pages in the “.pug” format and Pug will read that file, inject some dynamic data into it and return standard HTML. The example below is how you would write the code in Pug to create the same HTML as the Emmet example (above).
A Pug file uses indentation alone to indicate nesting. It can iterate over values to generate large amounts of HTML in one pass. These “.pug” files are designed to be reused many times across a project. Pug is available to install from package manager npm (opens in new tab) . But, if you want more information on how to get started with Pug pay a visit to the website (opens in new tab) .
This content originally appeared in Web Designer magazine.
- 10 best CSS frameworks
- CSS animation examples to recreate
- 8 HTML tags you need to be using (and 5 to avoid)
Thank you for reading 5 articles this month* Join now for unlimited access
Enjoy your first month for just £1 / $1 / €1
*Read 5 free articles per month without a subscription
Join now for unlimited access
Try first month for just £1 / $1 / €1
Get Weekly Tips and Inspiration
Sign up below to get the latest from Creative Bloq, plus exclusive special offers, direct to your inbox!
Matt Crouch is a front end developer who uses his knowledge of React, GraphQL and Styled Components to build online platforms for award-winning startups across the UK. He has written a range of articles and tutorials for net and Web Designer magazines covering the latest and greatest web development tools and technologies.
Related articles
How to Convert HTML to JSP
JSP allows you to embed snippets of the Java programming language into HTML tags to create interactive content. HTML pages are static in that each time a user loads the page, the content will appear the same. JSP allows for dynamic content to be added to HTML pages, so that each time the user reloads the page, the content changes. For example, we will go through a sample where every time a user reloads the page, the date and time are changed automatically to reflect the current date and time.
Advertisement
Open a new page in Notepad. Type the beginning and closing HTML tags with some space in between both tags. This specifies that the content will be in HTML.
Video of the Day
Type the opening body tag in the line below
Insert the following line at the top before the
This line declares that we are importing the java.util package because we will be using the date function. Java packages consist of classes of related functions.
Insert the following tag after the
Save the page with a .jsp extension.
Report an Issue
Screenshot loading...
TABLE OF CONTENTS (HIDE)
Java server-side programming, getting started with jsp by examples, introduction.
JavaServer Page (JSP) is Java's answer to the popular Microsoft's Active Server Pages (ASP). JSP, like ASP, provides a simplified and fast mean to generate dynamic web contents. It allows you to mix static HTML with dynamically generated HTML - in the way that the business logic and the presentation are well separated.
The advantages of JSP are:
- Separation of static and dynamic contents : JSP enables the separation of static contents from dynamic contents. The dynamic contents are generated via programming logic and inserted into the static template . This greatly simplifies the creation and maintenance of web contents.
- Reuse of components and tag libraries: The dynamic contents can be provided by reusable components such as JavaBean, Enterprise JavaBean (EJB) and tag libraries - you do not have to re-inventing the wheels.
- Java's power and portability
JSPs are Internally Compiled into Java Servlets
That is to say, anything that can be done using JSPs can also be accomplished using Java servlets. However, it is important to note that servlets and JSPs are complementary technologies, NOT replacement of each other. Servlet can be viewed as " HTML inside Java ", which is better for implementing business logic - as it is Java dominant. JSP, on the other hand, is " Java inside HTML ", which is superior for creating presentation - as it is HTML dominant. In a typical Model-View-Control (MVC) application, servlets are often used for the Controller (C), which involves complex programming logic. JSPs are often used for the View (V), which mainly deals with presentation. The Model (M) is usually implemented using JavaBean or EJB.
Apache Tomcat Server
JSPs, like servlets, are server-side programs run inside a HTTP server. To support JSP/servlet, a Java-capable HTTP server is required. Tomcat Server (@ http://tomcat.apache.org ) is the official reference implementation (RI) for Java servlet and JSP, provided free by Apache (@ http://www.apache.org ) - an open-source software foundation.
First JSP Example - " Java inside HTML "
Let's begin with a simple JSP example. We shall use the webapp called " hello " that we have created in our earlier exercise. Use a programming text editor to enter the following HTML/JSP codes and save as " first.jsp " (the file type of " .jsp " is mandatory) in your webapp (web context) home directory (i.e., " webapps\hello ".
To execute the JSP script: Simply start your Tomcat server and use a browser to issue an URL to browse the JSP page (i.e., http://localhost:8080/hello/first.jsp ).
From your browser, choose the "View Source" option to check the response message. It should be either of the followings depending on the random number generated.
It is important to note that the client is not able to "view" the original JSP script (otherwise, you may have security exposure), but merely the result generated by the script.
Explanations
- A JSP script is a regular HTML page containing Java programs. Recall that JSP is " Java inside HTML " (whereas servlet is " HTML inside Java "). The Java statements are enclosed by <% ... %> (called JSP scriptlet ) or <%= ... %> (called JSP expression ).
- JSP Scriptlet <% ... %> is used to include Java statements.
- JSP Expression <%= ... %> is used to evaluate a single Java expression and display its result.
- The method request.getRequestURI() is used to retrieve the URL of the current page . This is used in the anchor tag <a> for refreshing the page to obtain another random number.
Behind the Scene
When a JSP is first accessed, Tomcat converts the JSP into a servlet; compile the servlet, and execute the servlet. Check out the generated servlet for " first.jsp ", and study the JSP-to-servlet conversion. Look under Tomcat's " work\Catalina\localhost\hello " for " first_jsp.java ".
The relevant part of the generated servlet is extracted as follows (with some simplifications):
Explanation
- The HTML statements are written out as part of the response via out.write(), as "it is".
- The JSP scriptlets <% ... %> are kept, as "it is", in the converted servlet as the program logic.
- The JSP expressions <%= ... %> are placed inside a out.print() . Hence, the expression will be evaluated, and the result of the evaluation written out as part of the response message.
Compare the JSP script and the internally generated servlet, you shall understand that servlet is " HTML inside Java ", whereas JSP is " Java inside HTML ".
Subsequent accesses to the same JSP will be much faster, because they will be re-directed to the converted and compiled servlet directly (no JSP-to-servlet conversion and servlet compilation needed again), unless the JSP has been modified.
Revisit Java Servlets
A typical Java servlet (as shown below) contains three kinds of methods: init() , destroy() , and one or more service() methods such as doGet() and doPost() . init() runs when the servlet is loaded. destroy() runs when the servlet is unloaded. service() runs once per HTTP request. The service() methods takes two arguments: request and response , corresponding to the HTTP request and response messages respectively. A PrintWriter called out is created for writing out the response to the network.
Java servlet produces HTML codes by calling out.print() methods. You have to hardcode all the HTML tags (and cannot use any WYSIWYG web authoring tools). Any change to the web page's presentation (such as background color and font size) requires re-coding and re-compilation of servlet program. Servlet, in a nutshell, is " HTML inside Java ", whereas JSP is " Java inside HTML ".
Second JSP example - Echoing HTML Request Parameters
Enter the following JSP script and save as " echo.jsp " in your webapp's root directory .
Browse the JSP page created and study the generated servlet.
- This HTML page has a form with 3 checkboxes. The " name=value " pair of the checkboxes is " author=so_and_so " . No " action " attribute is specified, the default " action " is the current page (i.e. the query will be sent to the same page).
- The JSP scriptlet checks if the query parameter " author " exists to decide whether to dynamically generate the enclosed codes. " author " parameter is absent when the page is first requested. Once the client fills in the form (by checking the boxes) and submits the form, " author " will be present in the HTTP request, and submitted to the same page for processing (with the default <form> ’s " action " attribute).
- The request.getParameterValues() is used to retrieve all the values of the query parameter. The values are echoed back using an unordered list.
JSP Scripting Elements
JSP provides the following scripting elements:
- JSP Comment <%-- comments -->
JSP Expression <%= Java Expression %>
- JSP Scriptlet <% Java Statement(s) %>
JSP Directive <%@ page|include ... %>
To simplify the access of the HTTP request and response messages, JSP has pre-defined the following variables:
- request : corresponds to the HTTP request message.
- response : corresponds to the HTTP response message.
- out : corresponds to the HTTP response message’s output stream.
- others such as session , page , application , pageContext , which are outside the scope of this tutorial.
JSP comment <%-- comments --%>
JSP comments <%-- comments --%> are ignored by the JSP engine. For example,
Note that HTML comment is <!-- comments --> . JSP expression within the HTML comment will be evaluated. For example,
JSP Expression can be used to insert a single Java expression directly into the response message. This expression will be placed inside a out.print() method. Hence, the expression will be evaluated and printed out as part of the response message. Any valid Java expression can be used. There is no semi-colon at the end of the expression. For examples:
The above JSP expressions will be converted to:
You can use the pre-defined variables, such as request , in the expressions. For examples:
JSP Scriptlet <% Java statement(s) %>
JSP scriptlets allow you to do more complex operations than inserting a single Java expression (with the JSP expression). JSP scriptlets let you insert an arbitrary sequence of valid Java statement(s) into the service() method of the converted servlet. All the Java statements in a scriptlet are to be terminated with a semi-colon. For example:
In the converted servlet, the above will be inserted into the service() method as follows:
Notice that the Java codes inside a scriptlet are inserted exactly as they are written, and used as the programming logic. The HTML codes are passed to an out.write() method and written out as part of the response message.
JSP directives provide instructions to the JSP engine. The syntax of the JSP directive is:
JSP page Directive
The " page " directive lets you import classes and customize the page properties. For examples,
JSP include Directive
The " include " directive lets you include another file(s) at the time when the JSP page is compiled into a servlet. You can include any JSP files, or static HTML files. You can use include directive to include navigation bar, copyright statement, logo, etc. on every JSP pages. The syntax is:
For example:
JSP Database Example
Let's revisit our e-shop, which was created using Java Servlet.
Querying - " query.jsp "
Let's create the query page called " query.jsp ".
- This HTML page has a form with 3 checkboxes. The " name=value " pair of the checkboxes is " author=so_and_so ". No " action " attribute is specified, hence, it defaulted to current page. The processing script is contained in the same page.
- The method request.getParameter("author") is used to check if the query parameter " author " exists. " author " is absent during the first reference of the page.
- The <%@ page .. %> contains a JSP " page " directive to import the java.sql package.
- Establish a database connection via a java.sql.Connection object;
- Allocate a java.sql.Statement object under the Connection ;
- Prepare a SQL SELECT string;
- Execute the SQL SELECT using executeQuery() method. The result of query is returned in an object of java.sql.ResultSet ;
- Process the ResultSet row by row via ResultSet.next() ;
- Free resources and close the Connection .
- The query result is tabulated in a HTML table. Note the mixing of HTML and Java in producing the table.
Notice that JSP carries out the presentation much better and neater than servlet. The presentation can be changed easily with JSP. The JSP pages can be created and modified using a WYSIWYG web authoring tool and reload to see the effect on the presentation. Whereas, in the case of servlet, you have to explicitly code all the HTML tags inside the servlet program and re-compile the program.
Ordering - " order.jsp "
Let's write the " order.jsp " for processing the order, by updating the appropriate records in the database.
JSP Exercises
REFERENCES & RESOURCES
- JavaServer Pages Technology @ http://java.sun.com/products/jsp .
- Java Servlet Technology @ http://java.sun.com/products/servlet .
- Apache Tomcat @ http://tomcat.apache.org , Apache Software Foundation.
- The Java EE 5 Tutorial @ http://java.sun.com/javaee/5/docs/tutorial/doc/ .
- Marty Hall, et al., " Core Servlets and JavaServer Pages ", vol.1 (2nd eds, 2003) and vol. 2 (2nd eds, 2006), Prentice Hall.
- Java Database Connectivity (JDBC) @ http://java.sun.com/products/jdbc .
- RFC2616 " Hypertext Transfer Protocol HTTP 1.1 ", World-Wide-Web Consortium (W3C), June 1999.
- " HTML 4.01 Specification ", W3C Recommendation, 24 Dec 1999.
Latest version tested: Tomcat 7.0.32, JDK 1.7.0_07 Last modified: October, 2012
- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- About the company
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How to output HTML from JSP <%! ... %> block?
I just started learning JSP technology, and came across a wall.
How do you output HTML from a method in <%! ... %> JSP declaration block?
This doesn't work:
Server says there's no “out”.
U: I do know how to rewrite code with this method returning a string, but is there a way to do this inside <%! void () { } %> ? Though it may be non-optimal, it's still interesting.
8 Answers 8
You can't use the 'out' variable (nor any of the other "predeclared" scriptlet variables) inside directives.
The JSP page gets translated by your webserver into a Java servlet. Inside tomcats, for instance, everything inside scriptlets (which start "<%"), along with all the static HTML, gets translated into one giant Java method which writes your page, line by line, to a JspWriter instance called "out". This is why you can use the "out" parameter directly in scriptlets. Directives, on the other hand (which start with "<%!") get translated as separate Java methods.
As an example, a very simple page (let's call it foo.jsp):
would end up looking something like this (with a lot of the detail ignored for clarity):
- Thank you for your nice answer, though it isn't what I'm looking for. – ansgri Sep 26, 2008 at 16:48
- 3 The call to someOutput would not be placed in an out.write statement unless you used the expression syntax <%= %>. When you use the scriptlet syntax it is just inserted inline. – Garth Gilmour Sep 26, 2008 at 17:00
- 1 This is might not be the answer he was looking for but it was very informative. Thanks @Ashley Mercer – Abdelrahman Shoman Feb 18, 2018 at 5:19
Try this, it worked for me!

I suppose this would help:
Anyway, it isn't a good idea to have code in a view.
All you need to do is pass the JspWriter object into your method as a parameter i.e.
Then call it via:
The writer object is a local variable inside _jspService so you need to pass it into your utility method. The same would apply for all the other built in references (e.g. request, response, session).
A great way to see whats going on is to use Tomcat as your server and drill down into the 'work' directory for the '.java' file generated from your 'jsp' page. Alternatively in weblogic you can use the 'weblogic.jspc' page compiler to view the Java that will be generated when the page is requested.
A simple alternative would be the following:
The you could simply use the variable in any way within the jsp code
You can do something like this:
This will output test 1 2 3 to the page.
too late to answer it but this help others
- 2 The question is specifically about <%! %> , with the question mark. – ansgri Jul 17, 2013 at 11:13
Not the answer you're looking for? Browse other questions tagged jsp or ask your own question .
- The Overflow Blog
- How Intuit democratizes AI development across teams through reusability sponsored post
- The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie...
- Featured on Meta
- We've added a "Necessary cookies only" option to the cookie consent popup
- Launching the CI/CD and R Collectives and community editing features for...
- The [amazon] tag is being burninated
- Temporary policy: ChatGPT is banned
- Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2
Hot Network Questions
- What is the point of Thrower's Bandolier?
- What is temperature in the classical entropy definition?
- Hidden files on memory card
- Equation alignment in aligned environment not working properly
- Do new devs get fired if they can't solve a certain bug?
- Largest Binary Area
- Will DL360 Gen 8 servers fit in rails designed for DL360 Gen 7 servers?
- Is there a single-word adjective for "having exceptionally strong moral principles"?
- Rolling cube on an infinite chessboard
- Haunted house movie that focuses on a basement door and a ghost who wants to steal a mother's child
- Why do many companies reject expired SSL certificates as bugs in bug bounties?
- Loose bottom bracket on MTB
- Proper translation of 'bear with me'
- What video game is Charlie playing in Poker Face S01E07?
- How should I go about getting parts for this bike?
- Who owns code in a GitHub organization?
- Euler: “A baby on his lap, a cat on his back — that’s how he wrote his immortal works” (origin?)
- Tips for golfing in SVG
- Are there tables of wastage rates for different fruit and veg?
- Why do academics stay as adjuncts for years rather than move around?
- Amenable link groups
- Isolate page to turn off header
- std::to_array for multi dimensional array
- Conjugation of the Auxiliary Verb 得る When it's Read as うる
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .
HTML tags in JSP
In jsp we have the facility provided to use the html tag inside the JSP code.

In jsp we have the facility provided to use the html tag inside the JSP code.
The code of the program is given below:
- Creating a String
- Finding a Factorial using while loop
- JSP Simple Examples
- Calculate factorial Using Recursion
- Multiple Methods in Jsp
- Convert Celsius to Fahrenheit
- Two Indexes in For Loop
- Comments in Jsp
- Html tag inside out implicit object
- JSP methods
- Date in JSP
- If- Else Ladder
- Nested If Statements
- The Quintessential in JSP
- sendRedirect In JSP
- Snoop in jsp
- Request Headers in JSP
- How to include a File using directive and include action
- Specific Request Headers in JSP
- Java class in JSP
- Setting Colors in JSP
- Sine Table in JSP
- Applet In Jsp
- Creating a Local Variable in JSP
- Method in Declaration Tag
- Forward a JSP Page
- Literals in Jsp
- Jsp include directive
- Passing Parameters using
- Random in jsp
- Expression Language in JSP
- Tag Handler in JSP
- EL Basic Comparisons
- Expression Language Basic Arithmetic
- Implementing Conditional Content on a JSP Page
- Exception Handling in JSP
- Generate Error in JSP
- Using Operators in JSP
- Using Protected Access in JSP
- Coding Ground
- Corporate Training

- Basic JSP Tutorial
- JSP - Overview
- JSP - Environment Setup
- JSP - Architecture
- JSP - Lifecycle

JSP - Syntax
- JSP - Directives
- JSP - Actions
- JSP - Implicit Objects
- JSP - Client Request
- JSP - Server Response
- JSP - Http Status Codes
- JSP - Form Processing
- JSP - Writing Filters
- JSP - Cookies Handling
- JSP - Session Tracking
- JSP - File Uploading
- JSP - Handling Date
- JSP - Page Redirect
- JSP - Hits Counter
- JSP - Auto Refresh
- JSP - Sending Email
- Advanced JSP Tutorials
- JSP - Standard Tag Library
- JSP - Database Access
- JSP - XML Data
- JSP - Java Beans
- JSP - Custom Tags
- JSP - Expression Language
- JSP - Exception Handling
- JSP - Debugging
- JSP - Security
- JSP - Internationalization
- JSP Useful Resources
- JSP - Questions and Answers
- JSP - Quick Guide
- JSP - Useful Resources
- JSP - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
In this chapter, we will discuss Syntax in JSP. We will understand the basic use of simple syntax (i.e, elements) involved with JSP development.
Elements of JSP
The elements of JSP have been described below −
The Scriptlet
A scriptlet can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.
Following is the syntax of Scriptlet −
You can write the XML equivalent of the above syntax as follows −
Any text, HTML tags, or JSP elements you write must be outside the scriptlet. Following is the simple and first example for JSP −
NOTE − Assuming that Apache Tomcat is installed in C:\apache-tomcat-7.0.2 and your environment is setup as per environment setup tutorial.
Let us keep the above code in JSP file hello.jsp and put this file in C:\apache-tomcat7.0.2\webapps\ROOT directory. Browse through the same using URL http://localhost:8080/hello.jsp . The above code will generate the following result −

JSP Declarations
A declaration declares one or more variables or methods that you can use in Java code later in the JSP file. You must declare the variable or method before you use it in the JSP file.
Following is the syntax for JSP Declarations −
Following is an example for JSP Declarations −
JSP Expression
A JSP expression element contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file.
Because the value of an expression is converted to a String, you can use an expression within a line of text, whether or not it is tagged with HTML, in a JSP file.
The expression element can contain any expression that is valid according to the Java Language Specification but you cannot use a semicolon to end an expression.
Following is the syntax of JSP Expression −
Following example shows a JSP Expression −
The above code will generate the following result −
Today's date: 11-Sep-2010 21:24:25
JSP Comments
JSP comment marks text or statements that the JSP container should ignore. A JSP comment is useful when you want to hide or "comment out", a part of your JSP page.
Following is the syntax of the JSP comments −
Following example shows the JSP Comments −
A Test of Comments
There are a small number of special constructs you can use in various cases to insert comments or characters that would otherwise be treated specially. Here's a summary −
JSP Directives
A JSP directive affects the overall structure of the servlet class. It usually has the following form −
There are three types of directive tag −
We would explain the JSP directive in a separate chapter JSP - Directives
JSP Actions
JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin.
There is only one syntax for the Action element, as it conforms to the XML standard −
Action elements are basically predefined functions. Following table lists out the available JSP Actions −
We would explain JSP actions in a separate chapter JSP - Actions
JSP Implicit Objects
JSP supports nine automatically defined variables, which are also called implicit objects. These variables are −
We would explain JSP Implicit Objects in a separate chapter JSP - Implicit Objects .
Control-Flow Statements
You can use all the APIs and building blocks of Java in your JSP programming including decision-making statements, loops, etc.
Decision-Making Statements
The if...else block starts out like an ordinary Scriptlet, but the Scriptlet is closed at each line with HTML text included between the Scriptlet tags.
Now look at the following switch...case block which has been written a bit differentlty using out.println() and inside Scriptletas −
It's Wednesday.
Loop Statements
You can also use three basic types of looping blocks in Java: for, while, and do…while blocks in your JSP programming.
Let us look at the following for loop example −
Above example can be written using the while loop as follows −
JSP Operators
JSP supports all the logical and arithmetic operators supported by Java. Following table lists out all the operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom.
Within an expression, higher precedence operators will be evaluated first.
JSP Literals
The JSP expression language defines the following literals −
Boolean − true and false
Integer − as in Java
Floating point − as in Java
String − with single and double quotes; " is escaped as \", ' is escaped as \', and \ is escaped as \\.
Null − null

Introduction to JSP File
JSP File is used to create dynamic and fast loading web pages over the network. The file extension used for JSP Files is “.jsp”. For example test.jsp. JSP files contain a global tag “HTML” and under that tag JAVA coding is done to get the responsive feature added to the web platform. If there would not have been JAVA code added then the web page would have been static. JSP files are often considered similar to JAVA servlets if we consider the usage but the added advantage to JSP files is the separation of page design and business logic.

How to Create a File in JSP?
One can create a JSP file just like an HTML file but the difference is that a JSP file should be saved with an extension of “.jsp”. It also should have “<html>” tags in the start or end of file. Once these tags are declared then inside html tags JAVA code can be inline. Also, a JSP file can be created separately as a standalone file and then a JSP file can be included in another file like JAVA servlets. Any IDE (Integrated Development Environment) like Eclipse or netbeans can be used to create a new “ dynamic web project”. Providing relevant information like name of main class, requirement of xml descriptors and other details a web project can be created. Once a project is created, a new JSP page can be created in the “WEB-INF” folder under the project.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
File operations in JSP, JSP pages are compiled once and well connected with servlets or JSP as per the project requirements.
There are three tags used to do file operations in JSP and these are:
- Scriptlet Tag: This tag is used to script JAVA code in JSP pages. This tag looks like < % out.print( ” you are using scriptlet tag in JSP page to inline JAVA code ” ); % > . Here the “out.print()” function in AVA code is used to print the desired statement on the output screen. Variable declarations or control statements can also be included under this tag.
- Expression Tag: This tag is used to stream the outputs on the web page. It is to replace the function called “print()”. The tags look like: < %= ” You are using expression tag in JSP.. ” % > . This tag is used in the below provided examples as well.
- Declaration Tag: This tag is used to declare fields and methods in JSP pages. This tag does not use memory allocation since it is kept out of service() method of auto generated servlet. The JSP declaration tag looks like: < %! ..This is Declaration tag in JSP to declare methods or fields.. % >
Examples of JSP File
Given below are the examples mentioned :
test1JSP project

Explanation:
- In this example, HTML tags are declared. In the HTML tags CSS can be applied by creating a separate global CSS sheet and be included in the JSP file.
- CSS can be included inline locally as well if usage of CSS is limited. In this example a web page titled “ Example of JSP file” is created.
- The character set is used using an attribute of the “meta” tag named “charset” and assigned UTF-8 as value to it. The output screen contains a statement showing up from JSP code.
- Inline JSP code should be written under tage “<%= ….. JSP Code ….. %>”.

- In this example, the JSP file with an extension “.jsp” is created under the “WEB-INF” folder. Like explained in the previous example, html tags should be used and under that JSP code can be inlined. The title of this page is titled as “Example 2 in JSP”. A variable is declared under the JSP tag of data type double and named “num”.
- “Num” is assigned with the value of “Math.random()”. This function is stored in JAVA library to generate and return a random number. The example then has an “if-else” control statement to check if the random value is more than “0.95” or not. If the condition is satisfied then data is loaded from the if section.
- If the condition is not met then the data from the else section is printed on the output screen. Finally a self referencing link is provided under “<a> </a>” tag. The function used for self referencing is “request.getRequestURI()”. If this link is clicked again then the content is loaded again. The new content loaded generates new random numbers and uses “if/else” logic to print the output screen.
JSP pages are a lightweight and quick method to create dynamic web content. The content can be loaded on the fly over the network without much overheads while data exchange. The best advantage offered by JSP pages is the division of “design” and “business logic”. The business logic shows up under JAVA code while design comes from HTML (Hypertext markup language) and CSS (Cascading style sheet). This division simplifies developer’s work and promotes easier project maintenance. JSP is one of the most elegant ways of generating projects on web dynamic development.
Recommended Articles
This is a guide to JSP File. Here we discuss how to create a file in JSP along with programming examples respectively. You may also have a look at the following articles to learn more –
- JSP Error Page
- JSP Login Page
- JSP Formatter

Related Courses

*Please provide your correct email id. Login details for this Free course will be emailed to you
By signing up, you agree to our Terms of Use and Privacy Policy .
Forgot Password?
This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Explore 1000+ varieties of Mock tests View more
Submit Next Question

// Tutorial //
Jsp example tutorial for beginners.

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
Welcome to the JSP Example Tutorial for Beginners. In last few posts, a wrote a lot about Java Servlet and got very good response from our readers. So I have started another series on JSP tutorials and this is the first post of the series.
JSP Example Tutorial

JSP Tutorial
What is jsp and why do we need jsp, advantages of jsp over servlets, life cycle of jsp page, life cycle methods of jsp, simple jsp example with eclipse and tomcat, jsp files location in web application war file, jsp api interfaces and classes, jsppage interface, httpjsppage interface, jspwriter abstract class, jspcontext abstract class, pagecontext abstract class, jspfactory abstract class, jspengineinfo abstract class, errordata final class, jspexception class, jsptagexception class, skippageexception class, jsp comments, jsp scriptlets, jsp expression, jsp directives, jsp declaration, jsp transformed servlet source code and class file location in tomcat, jsp init parameters, overriding jsp init() method, attributes in a jsp.
JSP (JavaServer Pages) is server side technology to create dynamic java web application . JSP can be thought as an extension to servlet technology because it provides features to easily create user views. JSP Page consists of HTML code and provide option to include java code for dynamic content. Since web applications contain a lot of user screens, JSPs are used a lot in web applications. To bridge the gap between java code and HTML in JSP, it provides additional features such as JSP Tags, Expression Language, Custom tags. This makes it easy to understand and helps a web developer to quickly develop JSP pages.
- We can generate HTML response from servlets also but the process is cumbersome and error prone, when it comes to writing a complex HTML response, writing in a servlet will be a nightmare. JSP helps in this situation and provide us flexibility to write normal HTML page and include our java code only where it’s required.
- JSP provides additional features such as tag libraries, expression language, custom tags that helps in faster development of user views.
- JSP pages are easy to deploy, we just need to replace the modified page in the server and container takes care of the deployment. For servlets, we need to recompile and deploy whole project again.Actually Servlet and JSPs compliment each other. We should use Servlet as server side controller and to communicate with model classes whereas JSPs should be used for presentation layer.
JSP life cycle is also managed by container. Usually every web container that contains servlet container also contains JSP container for managing JSP pages. JSP pages life cycle phases are:
- Translation - JSP pages doesn’t look like normal java classes, actually JSP container parse the JSP pages and translate them to generate corresponding servlet source code. If JSP file name is home.jsp, usually its named as home_jsp.java.
- Compilation - If the translation is successful, then container compiles the generated servlet source file to generate class file.
- Class Loading - Once JSP is compiled as servlet class, its lifecycle is similar to servlet and it gets loaded into memory.
- Instance Creation - After JSP class is loaded into memory, its object is instantiated by the container.
- Initialization - The JSP class is then initialized and it transforms from a normal class to servlet. After initialization, ServletConfig and ServletContext objects become accessible to JSP class.
- Request Processing - For every client request, a new thread is spawned with ServletRequest and ServletResponse to process and generate the HTML response.
- Destroy - Last phase of JSP life cycle where it’s unloaded into memory.
JSP lifecycle methods are:
- jspInit() declared in JspPage interface. This method is called only once in JSP lifecycle to initialize config params.
- _jspService(HttpServletRequest request, HttpServletResponse response) declared in HttpJspPage interface and response for handling client requests.
- jspDestroy() declared in JspPage interface to unload the JSP from memory.
JspPage interface extends Servlet interface and declares jspInit() and jspDestroy() life cycle methods of the JSP pages.
HttpJspPage interface describes the interaction that a JSP Page Implementation Class must satisfy when using the HTTP protocol. This interface declares the service method of JSP page for HTTP protocol as public void _jspService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException .
Similar to PrintWriter in servlets with additional facility of buffering support. This is one of the implicit variables in a JSP page with name “out”. This class extends java.io.Writer and container provide their own implementation for this abstract class and use it while translating JSP page to Servlet. We can get it’s object using PageContext.getOut() method. Apache Tomcat concrete class for JspWriter is org.apache.jasper.runtime.JspWriterImpl .
JspContext serves as the base class for the PageContext class and abstracts all information that is not specific to servlets. The JspContext provides mechanism to obtain the JspWriter for output, mechanism to work with attributes and API to manage the various scoped namespaces.
PageContext extends JspContext to provide useful context information when JSP is used for web applications. A PageContext instance provides access to all the namespaces associated with a JSP page, provides access to several page attributes, as well as a layer above the implementation details. Implicit objects are added to the pageContext automatically.
The JspFactory is an abstract class that defines a number of factory methods available to a JSP page at runtime for the purposes of creating instances of various interfaces and classes used to support the JSP implementation.
The JspEngineInfo is an abstract class that provides information on the current JSP engine.
Contains information about an error, for error pages.
A generic exception known to the JSP container, similar to ServletException.If JSP pages throw JspException then errorpage mechanism is used to present error information to user.
Exception to be used by a Tag Handler to indicate some unrecoverable error.
Exception to indicate the calling page must cease evaluation. Thrown by a simple tag handler to indicate that the remainder of the page must not be evaluated. This exception should not be thrown manually in a JSP page.
Thats all for JSP example tutorial for beginners. I hope it helps you in understanding the basic concepts of JSPs and help you in getting started. We will look into other JSP features in future posts.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Learn more about us
Still looking for an answer?
very nice description sir… thanks.
- supriya kavade
can you please add some more example on custom tag
The ide i use is Intellij idea, but i cannot find the jsp transformed source files and servlet classes
Hello Pankaj, Your articles are really nice but only problem are the frequent pop-ups which really destruct the concentration. It will be really nice if you shift them to the bottom/top or on side bars. Warm Regards Rony
- Rony Ghosh
excuse me, please help i have problem in jsp thanks org.apache.jasper.JasperException: An exception occurred processing JSP page /dokter.jsp at line 14 11: 12: 13: <% 14: DokterController dk = new DokterController(); 15: String dokid = “”; 16: String doknamadokter = “”; 17: String doktempattgllahir = “”;
Java scriptlets(())have been obsolete and discredited since the introduction of JSP 2.0 and there are many good reasons not to use Java scriptlets in JSPs 1. Readability 2. Reusability 3. Maintainability 4. Scriptlets Break OOP
good Tutorial, thanks
- Cara Mengunci Folder
Thanks a lot, for posting tutorials on JSP.
- Rakhi Dhavale
Nice tutorial …

Popular Topics
- Linux Basics
- All tutorials
- Free Managed Hosting
Try DigitalOcean for free
Join the tech talk.
Please complete your information!
write html in jsp

Life called,so here I am.<br />Cheers<br />Niki.:-)

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf

- Design Pattern
JSP Tutorial
- Send your Feedback to [email protected]
Help Others, Please Share

Learn Latest Tutorials

Transact-SQL

Reinforcement Learning

R Programming

React Native

Python Design Patterns

Python Pillow

Python Turtle

Preparation

Verbal Ability

Interview Questions

Company Questions
Trending Technologies

Artificial Intelligence

Cloud Computing

Data Science

Machine Learning

B.Tech / MCA

Data Structures

Operating System

Computer Network

Compiler Design

Computer Organization

Discrete Mathematics

Ethical Hacking

Computer Graphics

Software Engineering

Web Technology

Cyber Security

C Programming

Control System

Data Mining

Data Warehouse
Javatpoint Services
JavaTpoint offers too many high quality services. Mail us on [email protected] , to get more information about given services.
- Website Designing
- Website Development
- Java Development
- PHP Development
- Graphic Designing
- Digital Marketing
- On Page and Off Page SEO
- Content Development
- Corporate Training
- Classroom and Online Training
Training For College Campus
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected] Duration: 1 week to 2 week

- Data Structure & Algorithm Classes (Live)
- System Design (Live)
- DevOps(Live)
- Explore More Live Courses
- Interview Preparation Course
- Data Science (Live)
- GATE CS & IT 2024
- Data Structure & Algorithm-Self Paced(C++/JAVA)
- Data Structures & Algorithms in Python
- Explore More Self-Paced Courses
- C++ Programming - Beginner to Advanced
- Java Programming - Beginner to Advanced
- C Programming - Beginner to Advanced
- Android App Development with Kotlin(Live)
- Full Stack Development with React & Node JS(Live)
- Java Backend Development(Live)
- React JS (Basic to Advanced)
- JavaScript Foundation
- Complete Data Science Program(Live)
- Mastering Data Analytics
- CBSE Class 12 Computer Science
- School Guide
- All Courses
- Linked List
- Binary Tree
- Binary Search Tree
- Advanced Data Structure
- All Data Structures
- Asymptotic Analysis
- Worst, Average and Best Cases
- Asymptotic Notations
- Little o and little omega notations
- Lower and Upper Bound Theory
- Analysis of Loops
- Solving Recurrences
- Amortized Analysis
- What does 'Space Complexity' mean ?
- Pseudo-polynomial Algorithms
- Polynomial Time Approximation Scheme
- A Time Complexity Question
- Searching Algorithms
- Sorting Algorithms
- Graph Algorithms
- Pattern Searching
- Geometric Algorithms
- Mathematical
- Bitwise Algorithms
- Randomized Algorithms
- Greedy Algorithms
- Dynamic Programming
- Divide and Conquer
- Backtracking
- Branch and Bound
- All Algorithms
- Company Preparation
- Practice Company Questions
- Interview Experiences
- Experienced Interviews
- Internship Interviews
- Competitive Programming
- Design Patterns
- System Design Tutorial
- Multiple Choice Quizzes
- Go Language
- Tailwind CSS
- Foundation CSS
- Materialize CSS
- Semantic UI
- Angular PrimeNG
- Angular ngx Bootstrap
- jQuery Mobile
- jQuery EasyUI
- React Bootstrap
- React Rebass
- React Desktop
- React Suite
- ReactJS Evergreen
- ReactJS Reactstrap
- BlueprintJS
- TensorFlow.js
- English Grammar
- School Programming
- Number System
- Trigonometry
- Probability
- Mensuration
- Class 8 Syllabus
- Class 9 Syllabus
- Class 10 Syllabus
- Class 8 Notes
- Class 9 Notes
- Class 10 Notes
- Class 11 Notes
- Class 12 Notes
- Class 8 Maths Solution
- Class 9 Maths Solution
- Class 10 Maths Solution
- Class 11 Maths Solution
- Class 12 Maths Solution
- Class 7 Notes
- History Class 7
- History Class 8
- History Class 9
- Geo. Class 7
- Geo. Class 8
- Geo. Class 9
- Civics Class 7
- Civics Class 8
- Business Studies (Class 11th)
- Microeconomics (Class 11th)
- Statistics for Economics (Class 11th)
- Business Studies (Class 12th)
- Accountancy (Class 12th)
- Macroeconomics (Class 12th)
- Machine Learning
- Data Science
- Mathematics
- Operating System
- Computer Networks
- Computer Organization and Architecture
- Theory of Computation
- Compiler Design
- Digital Logic
- Software Engineering
- GATE 2024 Live Course
- GATE Computer Science Notes
- Last Minute Notes
- GATE CS Solved Papers
- GATE CS Original Papers and Official Keys
- GATE CS 2023 Syllabus
- Important Topics for GATE CS
- GATE 2023 Important Dates
- Software Design Patterns
- HTML Cheat Sheet
- CSS Cheat Sheet
- Bootstrap Cheat Sheet
- JS Cheat Sheet
- jQuery Cheat Sheet
- Angular Cheat Sheet
- Facebook SDE Sheet
- Amazon SDE Sheet
- Apple SDE Sheet
- Netflix SDE Sheet
- Google SDE Sheet
- Wipro Coding Sheet
- Infosys Coding Sheet
- TCS Coding Sheet
- Cognizant Coding Sheet
- HCL Coding Sheet
- FAANG Coding Sheet
- Love Babbar Sheet
- Mass Recruiter Sheet
- Product-Based Coding Sheet
- Company-Wise Preparation Sheet
- Array Sheet
- String Sheet
- Graph Sheet
- ISRO CS Original Papers and Official Keys
- ISRO CS Solved Papers
- ISRO CS Syllabus for Scientist/Engineer Exam
- UGC NET CS Notes Paper II
- UGC NET CS Notes Paper III
- UGC NET CS Solved Papers
- Campus Ambassador Program
- School Ambassador Program
- Geek of the Month
- Campus Geek of the Month
- Placement Course
- Testimonials
- Student Chapter
- Geek on the Top
- Geography Notes
- History Notes
- Science & Tech. Notes
- Ethics Notes
- Polity Notes
- Economics Notes
- UPSC Previous Year Papers
- SSC CGL Syllabus
- General Studies
- Subjectwise Practice Papers
- Previous Year Papers
- SBI Clerk Syllabus
- General Awareness
- Quantitative Aptitude
- Reasoning Ability
- SBI Clerk Practice Papers
- SBI PO Syllabus
- SBI PO Practice Papers
- IBPS PO 2022 Syllabus
- English Notes
- Reasoning Notes
- Mock Question Papers
- IBPS Clerk Syllabus
- Apply for a Job
- Apply through Jobathon
- Hire through Jobathon
- All DSA Problems
- Problem of the Day
- GFG SDE Sheet
- Top 50 Array Problems
- Top 50 String Problems
- Top 50 Tree Problems
- Top 50 Graph Problems
- Top 50 DP Problems
- Solving For India-Hackthon
- GFG Weekly Coding Contest
- Job-A-Thon: Hiring Challenge
- BiWizard School Contest
- All Contests and Events
- Saved Videos
- What's New ?
- Data Structures
- Interview Preparation
- Topic-wise Practice
- Latest Blogs
- Write & Earn
- Web Development
Related Articles
- Write Articles
- Pick Topics to write
- Guidelines to Write
- Get Technical Writing Internship
- Write an Interview Experience
- Java Applet Basics
- Web Browsers that support Java Applets and how to enable them
- Difference between Applets and Servlets
- Introduction to Java Servlets
Introduction to JSP
- Life cycle of JSP
- Life Cycle of a Servlet
- Difference between Servlet and JSP
- Starting with first Servlet Application
- The HttpSession Interface in Servlet
- URL Rewriting using Java Servlet
- Servlet Collaboration In Java Using RequestDispatcher and HttpServletResponse
- Java Servlet and JDBC Example | Insert data in MySQL
- Establishing JDBC Connection in Java
- How is Java platform independent?
- JDBC Drivers
- Is main method compulsory in Java?
- Myth about the file name and class name in Java
- How to run java class file which is in different directory?
- Arrays in Java
- Spring Boot - Start/Stop a Kafka Listener Dynamically
- Parse Nested User-Defined Functions using Spring Expression Language (SpEL)
- Split() String method in Java with examples
- Arrays.sort() in Java with examples
- For-each loop in Java
- Reverse a string in Java
- Object Oriented Programming (OOPs) Concept in Java
- How to iterate any Map in Java
- HashMap in Java with Examples
- Initialize an ArrayList in Java
- Difficulty Level : Easy
- Last Updated : 23 Nov, 2022
Introduction
- It stands for Java Server Pages .
- It is a server side technology.
- It is used for creating web application.
- It is used to create dynamic web content.
- In this JSP tags are used to insert JAVA code into HTML pages.
- It is an advanced version of Servlet Technology.
- It is a Web based technology helps us to create dynamic and platform independent web pages.
- In this, Java code can be inserted in HTML/ XML pages or both.
- JSP is first converted into servlet by JSP container before processing the client’s request.
JSP pages are more advantageous than Servlet:
- They are easy to maintain.
- No recompilation or redeployment is required.
- JSP has access to entire API of JAVA .
- JSP are extended version of Servlet.
Features of JSP
- Coding in JSP is easy :- As it is just adding JAVA code to HTML/XML.
- Reduction in the length of Code :- In JSP we use action tags, custom tags etc.
- Connection to Database is easier :-It is easier to connect website to database and allows to read or write data easily to the database.
- Make Interactive websites :- In this we can create dynamic web pages which helps user to interact in real time environment.
- Portable, Powerful, flexible and easy to maintain :- as these are browser and server independent.
- No Redeployment and No Re-Compilation :- It is dynamic, secure and platform independent so no need to re-compilation.
- Extension to Servlet :- as it has all features of servlets, implicit objects and custom tags
JSP syntax Syntax available in JSP are following
- Declaration Tag :-It is used to declare variables.
- Java Scriplets :- It allows us to add any number of JAVA code, variables and expressions.
- JSP Expression :- It evaluates and convert the expression to a string.
- JAVA Comments :- It contains the text that is added for information which has to be ignored.
Process of Execution Steps for Execution of JSP are following:-
- Create html page from where request will be sent to server eg try.html.
- To handle to request of user next is to create .jsp file Eg. new.jsp
- Create project folder structure.
- Create XML file eg my.xml.
- Create WAR file.
- Start Tomcat
- Run Application
Example of Hello World We will make one .html file and .jsp file
Advantages of using JSP
- It does not require advanced knowledge of JAVA
- It is capable of handling exceptions
- Easy to use and learn
- It contains tags which are easy to use and understand
- Implicit objects are there which reduces the length of code
- It is suitable for both JAVA and non JAVA programmer
Disadvantages of using JSP
- Difficult to debug for errors.
- First time access leads to wastage of time
- It’s output is HTML which lacks features.
Please Login to comment...
- susmitadey475
Improve your Coding Skills with Practice
Start your coding journey now.
- Previous : Chapter 4 Java Servlet Technology
- Next : The Example JSP Pages
A Simple JSP Page Example
The web page in Figure 5–1 is a form that allows you to select a locale and displays the date in a manner appropriate to the locale.
Figure 5–1 Localized Date Form
The source code for this example is in the tut-install /javaeetutorial5/examples/web/date/ directory. The JSP page, index.jsp , appears below; it is a typical mixture of static HTML markup and JSP elements. If you have developed web pages, you are probably familiar with the HTML document structure statements ( <head> , <body> , and so on) and the HTML statements that create a form ( <form> ) and a menu ( <select> ).
The lines in bold in the example code contain the following types of JSP constructs:
A page directive ( <%@page ... %> ) sets the content type returned by the page.
Tag library directives ( <%@taglib ... %> ) import custom tag libraries.
jsp:useBean is a standard element that creates an object containing a collection of locales and initializes an identifier that points to that object.
JSP expression language expressions ( ${ } ) retrieve the value of object properties. The values are used to set custom tag attribute values and create dynamic content.
Custom tags (see Chapter 8, Custom Tags in JSP Pages ) set a variable ( c:set ), iterate over a collection of locale names ( c:forEach ), and conditionally insert HTML text into the response ( c:if , c:choose , c:when , c:otherwise ).
jsp:setProperty is another standard element that sets the value of an object property.
A function ( f:equals ) tests the equality of an attribute and the current item of a collection. (A built-in == operator is usually used to test equality.)
Here is the JSP page:
To deploy the date application with NetBeans IDE, follow these steps:
Start the Application Server.
In NetBeans IDE, select File->Open Project.
In the Open Project dialog, navigate to:
Select the date folder.
Select the Open as Main Project check box.
Click Open Project.
In the Projects tab, right-click the date project, and select Undeploy and Deploy.
To deploy the date application with the Ant tool, follow these steps:
In a terminal window, go to tut-install /javaeetutorial5/examples/web/date/ .
Type ant . This command will spawn any necessary compilations, copy files to the tut-install /javaeetutorial5/examples/web/date/build/ directory, and create a WAR file.
Type ant deploy .
To run the example, do the following:
Set the character encoding in your browser to UTF-8.
Open your browser to http://localhost:8080/date .
You will see a combo box whose entries are locales. Select a locale and click Get Date. You will see the date expressed in a manner appropriate for that locale.
Some of the characters might not display properly if you don’t have the appropriate language files installed on your machine. Consult the user guide or online help for your operating system to determine how you can install these language files.
- © 2010, Oracle Corporation and/or its affiliates

IMAGES
VIDEO
COMMENTS
HTML is to a website what a solid foundation is to a house. Without HTML code, web developers wouldn’t have anything to build on. In other words, you wouldn’t be able to read this article without proper HTML code. Learn more about how this ...
Speed up your HTML and CSS workflow using Emmet and Pug. Creative Bloq is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission. Learn more By Matt Crouch ( Web Designer ) published 9 De...
JSP allows you to embed snippets of the Java programming language into HTML tags to create interactive content. HTML pages are static in that each time a user loads the page, the content will appear the same. JSP allows you to embed snippet...
2. First JSP Example - "Java inside HTML" · A JSP script is a regular HTML page containing Java programs. Recall that JSP is "Java inside HTML" (whereas servlet
The JSP page gets translated by your webserver into a Java servlet. Inside tomcats, for instance, everything inside scriptlets (which start "<%")
In this JSP Tutorial, we will see how to include html file inside a JSP page using include page directive.Code Snippet:
In jsp we have the facility provided to use the html tag inside the JSP code. In this example we have used the html tag inside the println() method of the out
A JSP expression element contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP
The file extension used for JSP Files is “.jsp”. For example test.jsp. JSP files contain a global tag “HTML” and under that tag JAVA coding is done to get the
Since web applications contain a lot of user screens, JSPs are used a lot in web applications. To bridge the gap between java code and HTML in
To add html in jsp you need to include it in the out.println() function. ... out.println("<meta HTTP-EQUIV=\"REFRESH\" content=\"1; url=http://
To create the first JSP page, write some HTML code as given below, and save it by .jsp extension. We have saved this file as index.jsp. Put it in a folder
It stands for Java Server Pages. · It is a server side technology. · It is used for creating web application. · It is used to create dynamic web
The JSP page, index.jsp , appears below; it is a typical mixture of static HTML markup and JSP elements. If you have developed web pages, you are probably