Tuesday, August 24, 2010

JSP web site tutorial (Hello World)

JSP simply puts Java inside HTML pages.
The Java code is embedded between the notations <% and %> and it is called Scriptlet.
To create first JSP page:
1. Download Eclipse IDE for Java EE Developers from http://www.eclipse.org/downloads/
2. Unzip it and Install Eclipse IDE.
3. Launch Eclipse by clicking eclipse.exe
4. Click File=>New=>Project=>Web=>Dynamic Web Project
5. Click Next button
6. Put hello in Project name and select 2.3 in Dynamic web module version















7. Click Finish button
8. Right-click on WebContent and click New=>JSP file
9. Replace following code with
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >

<%String str = "Hello World";%>

<html>

<head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body>

<%=str%>

</body>

</html>
10. Click File=>Save
11. Right-click your hello project.
12. Click Export=>war file
13. In Destination, put c:\hello.war and click Finish button
Now you need publish your Hello World jsp on internet. I found a good JPS hosting company EATJ.com http://www.eatj.com/ . They have free trial account. You can get your hosting space immediately, once you register on EATJ.
14. Once your EATJ account is activated, login to your EATJ account. Scroll down, you will find UPLOAD WAR FILES section. Click Browser button and go to c:\ and find your hello.war and click Upload button.
15. Click Restart link. You will see something like http://<username>.<hostname>.eatj.com/
16. Click this link. You will see Tomcat page.
17. Append hello/hello.jsp in your URL such as http://<username>.<hostname>.eatj.com/hello/hello.jsp

For this tutorial source code, you can download it at http://www.postpart.com/hello.war

Database tutorial: http://jspjdbc.blogspot.com/



More tutorials: http://jsptutorblog.blogspot.com/