This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
    Bookmark Topic Watch Topic
  • New Topic

How to run jsp on TOMCAT?

 
Suzana Shah
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
I m new to this JSP, and i have installed Tomcat version 3.3. I got tomcat running and the jsp examples running fine. Now i m trying to run a simple jsp page where i want to display hello world. But i get an error. I saved the helloworld.jsp file in the following ROOT directory:
C:\jakarta-tomcat-3.3\webapps\ROOT\helloworld.jsp
and i try to run it on the web browser by typing:
http://localhost:8080/root/helloworld.jsp

but i get an error file not found. I m pretty new to this,and maybe i m placing it in the wrong directory....or do i need to compile it? ....i m
Can anyone help?
Suzana
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Report post to moderator
Create a jsp folder under the webapps\ROOT\ directory and out it there. Access it by including jsp in the path.
 
durgesh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi
go to the folder where you have installed tomcat .. usually it is in program files/apache tomcat 4.0/webapps/examples/urfoldername
place ur just file in the urfoldername folder
and in the broswer type in the following url
http://localhost:8080/examples/jsp/urfoldername/select.jsp
hopes this helps
durgesh
 
Suzana Shah
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
Thanks for the suggestions, i have tried both ways, but for soem reason its not finding the file, every time i get this error on the tomcat server:
2002-01-20 17:46:37 - Ctx() : Status code:404 request:R( + /hello/hello.html +
null) msg:null
i have tried saving the hello.jsp under a folder called hello and then saved it under the webapps/ROOT directory, as well as doing it the other way such as saving it under webapps/examples/jsp/hello directory and i still get the same error....file not found...is there soemthing else which i m missing...i dont know...i can run the jsp examples fine....by typing as follows:
http://localhost:8080/examples/jsp/num/numguess.jsp
but when i try running my hello.jsp it cant find it..hellp.......can anyone explain if i m missing something
Thanks
Suzana
 
Suzana Shah
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi,
i realised something strange, i even tried creating a simple html file and then tried to view it from the browser but it gave me the same error, but when i restarted the tomcat server again during startup i got this message:
2002-01-20 17:55:52 - WorkDirSetup: Creating work dir C:\jakarta-tomcat-3.3\work\DEFAULT\hello
2002-01-20 17:55:52 - ContextManager: Adding DEFAULT:/hello
and then when i run the hello.html file from localhost it runs:
i type as follows:
http://localhost:8080/hello/hello.jsp
as i am saving the hello.html under the C:\jakarta-tomcat-3.3\webapps\hello directory
and now i can view the html file, but anything other then that gives me the file not found error...even if i put it under the hello directory....whats going on and why does tomcat display such message when starting up?
confused and lost..can anyone help......
pleaseeeeee,
Suzana
 
Sals Hamid
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Report post to moderator
Do u set paths for tomcat, if yes then write the following code
<%@ page language ="java" %>
<% out.println("Hello World"); %>
save it in Root in your folder.
try to open.
first check ur paths are right
 
Arokia Raj
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am unable to run Jsp file using apache tomcat.
but the examples given in the apace-tomcat package are running well.
Please help me.

Thank you,
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Arokia,

I assume you managed to run the jsp-examples when accessing http://localhost:8080/jsp-examples.

Okay, let's try running a Hello.jsp which displays date.

Hello.jsp


Now put this Hello.jsp file under C:\tomcat\webapps\Root. Open a browser and run this http://localhost:8080/Hello.jsp.

Please note that Tomcat is case-sensitive. So if you run http://localhost:8080/hello.jsp (small letter h), it won't work. Since your file is saved as Hello.jsp.

Joyce
[ November 19, 2004: Message edited by: Joyce Lee ]
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Report post to moderator
Continue...(part 2)

Let's say you don't want to place this Hello.jsp under C:\tomcat\webapps\Root directory. You want to create your own directory.

With the Tomcat shutdown, create a new directory called myproject under C:\tomcat\webapps. Place this Hello.jsp under C:\tomcat\webapps\myproject. In order for the Tomcat to recognise this myproject during deployment, you need to create an empty directory web-inf under C:\tomcat\webapps\myproject. Now startup the Tomcat and run this application http://localhost:8080/myproject/Hello.jsp

You might want to take a look at this thread.
[ November 19, 2004: Message edited by: Joyce Lee ]
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Report post to moderator
A Tutorial on Installing and Using Tomcat 4 or 5 for Servlet and JSP Development
 
Prasoona Rr
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Joyce,

the problem taht am facing si somewhat similar to the current thread. I'm written a jsp (Welcome) calling another one (Login.jsp). Once the login details are furnished in Login.jsp, it transfers control to ValidateServlet.
Validateservlet in turn calls a couple of other java user-defined classes.

The problem is as follows:
I placed the Welcome.jsp and Login.jsp in the webapps/root folder (Tomcat 5.0.24) I placed the ValidateServlet.java, User.java, DBConnection.java in C:\jakarta-tomcat-5.0.24\webapps\ROOT\WEB-INF\classes folder.
If i try to place the servlet details in the web.xml in the corresponding WEB-INF, while running the jsp with the command in IE browse
http://localhost:8080/Welcome.jsp

the response is "/Welcome.jsp resource not found"

if i remove the amendments that i did to web.xml, the jsp leads to Login.jsp without any problem, but further fails to locate ValidateServlet.

could ther ebe any problem with Login.jsp calling ValidateServlet. for ur ref. attaching the login.jsp code here.

<Html>
<body>

<%@ page language ="java"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>

<form action = "http://localhost:8080/servlet/ValidateServlet"
method = "POST">


<title> <head>Login Details</title></head>
<form>
<% if((request.getParameter("reply")).equals("yes"))
{ %>

<br> USERNAME
<input type = "text" name = "loginname" size = "10" > </br>
<br> PASSWORD
<input type = "password" name = "password" size = "10" > </br>
<br><input type = "submit" name = "submit" value = "SUBMIT" > </br>

<% }
else {

out.println("Thanks for visiting this page");
}

%>

</form>
</body>
</html>

sorry for such a verbose explanation, but need help badly.

Thanks,
Prasoona.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Prasoona,

If i try to place the servlet details in the web.xml in the corresponding WEB-INF, while running the jsp with the command in IE browse
http://localhost:8080/Welcome.jsp

the response is "/Welcome.jsp resource not found"

It could be the servlet details added incorrectly in the web.xml. As a result, the application could not be deployed.

Try to add this in the web.xml. Assuming ValidateServlet.class is in .../WEB-INF/classes directory.



if i remove the amendments that i did to web.xml, the jsp leads to Login.jsp without any problem, but further fails to locate ValidateServlet.
ValidateServlet class must be declared in the web.xml using <servlet> element otherwise it cannot be located.

Joyce
 
Prasoona Rr
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
Well well, within a few hrs of irritating my pc,I achieved my way. The code is working now. All that I had to do was follow the instructions as in Tomcat installation, specifically the "uncommenting of invoker" in web.xml in conf folder.

But the concept that I dont understand is "why should it not identify the first jsp at all, if i try to map the servlet in the corresponding web.xml file"

Please could anyone clarify this?

Thanks
Prasoona.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Report post to moderator
Well well, within a few hrs of irritating my pc,I achieved my way. The code is working now. All that I had to do was follow the instructions as in Tomcat installation, specifically the "uncommenting of invoker" in web.xml in conf folder.
I didn't uncomment the invoker. That's why I provided the <servlet-mapping> element in the WEB-INF/web.xml.
 
    Bookmark Topic Watch Topic
  • New Topic