JSP Example

JSP Example

Following is your simple JSP Example

File Name: Hello.jsp

Open in notepad with the file name "Hello.jsp" and type the following your simple program.


JSP Example
Output Screenshot of JSP Example

Your first JSP Example is over. You may wonder how it could be a JSP program where there is no Java or JSP code at all and everything is nothing but HTML code. You are right to think whether it is a HTML file or JSP file. But observe, the file extension is .jsp but not .html. Then what file it is? If you open Hello.jsp in a browser it does not execute. It should be opened through a JSP container. We know the JSP file comprises of a mixture static code written in HTML and dynamic code in JSP. As a special case and to check the JSP works or not being first program, here we have 100% static code and 0% dynamic code.

I use here a Tomcat Web Server which supplies both JSP container and Servlet container. As you can see in the browser prompt, the Tomcat is working on port number 8888. "india" is my own folder created in Tomcat "webapps" folder.

How to execute the above Hello.jsp?

a) Copy (known as deployment) the Hello.jsp file to india folder.
b)
Start the Tomcat server
c) Type in the browser prompt:
http://localhsot:8888/india/Hello.jsp
and press enter key. You will get above screen

Here there is no client program.

Note: Always take the help of your friend knowing Servlets and JSP for the execution of first program either Servlet or JSP.

Now let us modify the above program with some JSP elements. Now also there is no client program.


ima1
Output screenshot of JSP Example

The above code comprises of both static HTML code and dynamic JSP code. Lines "HTML code Line 1" and "This is HTML code Line 2" are static code. The dynamic code of printing for loop is placed with the elements <% and %>. JSP container understands any code placed within <% and %> is dynamic code. The code placed within <% and %> is known as scriptlet.

Let us write next program First JSP Example User Name and Password Login Validation involving client HTML file and server-side JSP file. Here client sends user name and password, server validates and send response to client of validation result.

Leave a Reply

Your email address will not be published. Required fields are marked *