Archive

Posts Tagged ‘extenstion-less’

The beginning of JSP

August 25, 2008 ppshein Leave a comment

There are so many extension-less web programming in Web developement environment such as Ruby, PHP, JSP and so on. Among them, I want to tell about the simple coding of JSP. Honestly, I’m just beginner to learn JSP, especially J2EE. Because, I just want to know some applications based on Sun Java. Ok, let’s go…

Here is simple JSP file and named as greeting.jsp

<html>
<body>
Hello World!
<br>
Current time is <%= new java.util.Date() %>
</body>
</html>

And create web.xml file and here is coding needed to be in this file.

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<!DOCTYPE web-app PUBLIC ‘-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN’ ‘http://java.sun.com/dtd/web-app_2_3.dtd’>
<web-app>
<display-name>Hello2</display-name>
<description>no description</description>
<servlet>
<servlet-name>greeting</servlet-name>
<display-name>greeting</display-name>
<description>no description</description>
<jsp-file>/greeting.jsp</jsp-file> <!– what gets called –>
</servlet>
<servlet-mapping>
<servlet-name>greeting</servlet-name>
<url-pattern>/greeting</url-pattern> <!– URL from browser –>
</servlet-mapping>
</web-app>

Then, open tomcat manager and create folder name as hello. Create build folder, then copy above greeting.jsp file in this folder, then create WEB-INF folder in build folder. Finally, web.xml file into WEB-INF.

Open your Internet Explorer or Firefox, and can run as http://localhost:8080/hello/greeting. How? It’s quite simple, right?

Categories: J2EE Tags: , ,