View Full Version : how to run jsp?

05-17-2007, 10:35 PM
I just installed the tomcat, but I dont know where to save my first jsp file, and how to run it in the browser by starting with http://

05-17-2007, 10:41 PM
Locate the directory where you have installed Tomcat.
In that directory...you should find another directory called webapps.

so, assuming that you have installed Tomcat on the C drive, you should now be in

That is the directory where you should create your JSP projects. So, create a new Directory in the "webapps" directory for your new project....and create any jsp files you wish to have...

Note...the structure of your project should be as follow (assuming that your project name is called "test_project"


The main file that you should note is "web.xml"....as you will need to specify all the necessary configurations for your project there. Look at the example projects installed when you installed Tomcat for a sample.


05-17-2007, 10:52 PM
Hi there, I can locate that webapps, but what about the URL? I want to run with Http:// not C:\ is there a way to configure that?

05-17-2007, 11:02 PM
by default...Tomcat will run at port 8080....unless you have changed during the installation

First, make sure that tomcat is currently running

Second, point your browser to http://localhost:8080

Once there, you will be able to set a default tomcat page. if you cannot see it...it could be due to any of the following reasons:-
1- The port is not 8080
2- Tomcat is not currently running

if it is the first one...please go and locate the following file


around line 76...see what is the port on your system...

<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />

If you don't like adding port 8080...or http://localhost:8080 you can change it to 80...and then you can write http://localhost

Another important file...you should look at is the following

Well..if you want to access the Tomcat Manager...then you should add the following two line

<role rolename="admin"/>
<user username="YOUR_USER_NAME_HERE" password="YOUR_PASSWORD_HERE" roles="admin,manager"/>

As for seeing your project, depending on what you have called your project...you should be able to see at http://localhost:8080/PROJECT_NAME


05-18-2007, 06:26 PM
I got that http://localhost:8080 to work, it takes me to JBoss page. But when I put http://localhost:8080/index.jsp.. it says page cannot be found. That index.jsp is in the webapps/ROOT

05-18-2007, 06:29 PM
<Connector port="8080" protocol="HTTP/1.1"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
redirectPort="8443" />
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

05-18-2007, 09:37 PM
try the following



05-18-2007, 10:52 PM
Not working ess :(

05-19-2007, 12:12 AM

Ok...here is a quick tutorial...

Go to your webapps folder and create a new folder and call it "test".

On my system, I have installed tomcat on the C drive...so, I will be creating a test folder in the following directory


That is your base directory for your project.

Now, let's create the other files and directories required for a web application according to Sun specification.

in the "test" folder create the following folders


the "web" folder can be used to store images, css, javascript and any other files

the "WEB-INF" folder is very important...as it contains the "web.xml" file which can be used for the purpose of configuring your application, url patterns etc

the "WEB-INF\classes" folder should be used for the purpose of storing Servlets

the "WEB-INF\lib" folder should be used to add thrid party jar files...such as JDBC drivers

Ok, now in the the WEB-INF folder, create an xml file and name it "web.xml"...so now, your WEB-INF should contain the following folders and an xml file
1- classes (folder)
2- lib (folder)
3- etc (folder)
4- web.xml (xml file)

Once you have created it, please paste the following contests in the "web.xml" file

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

<display-name>Testing Tomcat Configurations</display-name>
<description>This is a test project</description>

the web.xml file in this case...does not say much...it only specify the name of the project and a short description.

Ok...now we will create a new jsp file... which will be see once you have access the project.

In the main directory of your project "test", please create a file and name it "index.jsp"...so the result should be

Once you have created it, please paste the following code in the index.jsp file.

<%@ page language="java"%>
<%@ page import="java.util.Date" %>
<%@ page session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-language" content="en-GB" />
<title>Testing Tomcat Installations</title>
<h1>Testing Tomcat Configurations</h1>
// print out hello world
out.println( "Hello Wolrd of JSP Programming :)" );
<b>Time and Date: </b> <%= new Date() %>

Once you have created the page, please ensure that tomcat is running, before going to the following URL


I really hope that it work for you this time around...if not, let's know.


05-21-2007, 06:55 PM
Ess, still not working, man. This is the error I got:

HTTP Status 404 - /test/index.jsp


type Status report

message /test/index.jsp

description The requested resource (/test/index.jsp) is not available.


Apache Tomcat/5.5.9

Also, my tomcat is in Program files -> Apache -> then tomcat

05-22-2007, 02:23 AM
Sorry to hear you are still having problems cgibie.

the 404 error indicates that the page was not found.

If you have installed your tomcat in c:\Program Files\Apache\Tomcat

Then please open that directory as a starting point.

Once opened...you should find a folder called "webapps"

Important Note: The "webapps" folder is the location where you should create all of your JSP projects. So...to create a project, you do either of the following
1- Create a folder for your project in the webapps directory
2- Create a WAR file and deploy it using Tomcat Manager

In my previous post, I have tried to demonstrate creating a project using the first method.
Once again, please follow these steps.
1- open the webapps folder
2- inside the webapps folder, create a new folder ...click on file->new->folder...this will be the base for your project.
3- give the new folder a meaningful name (the name of your project i.e. test)

Once you have done that, open your newly created folder/project....and start creating the following folders inside it (By convention, you should create these folders...if you aren't going to use them)


Inside the WEB-INF, create the following folders

Inside the WEB-INF, create an XML file and call it web.xml
Copy the contents I posted in my previous post...into the web.xml file

Go back to your project folder (the base folder for your project)
and create index.jsp...and type anything you wish.

Visit http://localhost:8080/[project-name]

Here is a tutorial on JSP...it is not advanced...but a good starting point I guess.


And Another one


By the way, you can always use an IDE to help you learn the basics of JSP technology. I would recommend using Netbeans (http://netbeans.org)...as it comes bundled with Apache Tomcat...and all you have to do ...just create a new web application. Also...you can always find out about the structure of the project once you have used netbeans.


05-22-2007, 09:14 PM
ess I did that. when you posted those codes for me. I know that your codes are in your C:\. I did all those steps but still got above error. What else you want me to show you?

04-02-2009, 07:54 PM
ess I did that. when you posted those codes for me. I know that your codes are in your C:\. I did all those steps but still got above error. What else you want me to show you?
well i am also getting same error. please tell me if you have already solved

04-03-2009, 07:35 AM
Look at this tutorial, it explains how project directory structure is organized

Once you have jsp file ar right place, look at this link to learn how to start and stop the server

Look at Deploying the application to tomcat web container section to understand how to deploy your application to tomcat and how to access it in browser.