wood burning stoves 2.0*
The moose likes JSP and the fly likes JSP Newbie needs help getting a clue! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Newbie needs help getting a clue!" Watch "JSP Newbie needs help getting a clue!" New topic
Author

JSP Newbie needs help getting a clue!

icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
I got PHP, Perl, MySQL, ASP, etc....

I want Java JSP and all that jazz

I have successfully installed Tomcat and want to get started on some tutorials, but I get lost with servlets and beans.

I can compile my beans and servlets and stuff, but WHERE DO YOU PUT THEM!!

every time I try to reference anything, the server can't find them....

All these tutorials tell you how to write code - which comes easy for me - Its the setup and configureation I am lost with.

Could someone help me with some advise on how to configure tomecat so I know where to put beans and servlets

(also why servlets vs jsp vs beans )

I appreciate all your help..

Thanks James
icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
sorry... I know forgive me for my spelling...
I'm a programmer not an english scholar - or should that be skawlor
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

The Tomcat documentation includes info on how to set up a web app. The documentaion web app is already configured when you load Tomcat.

Quickie overview:

1) Create a folder to serve as the 'document base'. It can be anywhere on your system. If you want Tomcat to pick it up automatically put it in $CATALINA_HOME/webapps.

2) In this folder create a folder named WEB-INF.

3) In WEB-INF create folders classes and lib. Your class hierarchy (be sure that all classes are in packages other than the default) goes in classes. Any jar files your app needs go in lib.

4) Create your web.xml file in WEB-INF.

5) Create your JSPs and such. They can go in the root of your folder structure, or in any folder hierarchy therein. If you want to hide them from the world (so that they can only be accessed via their servlet controllers -- a good pattern to follow), place them in a folder hiearchy under WEB-INF.

Refer to the docs for any further details.
[ May 03, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
Thank you so much for your reply.

Please forgive me I get lost sometimes. I have tried to read through the documentation and it is fuzzy at best. Maybe I don't know what I am doing... I guess that is why I am here...

I have done what you have suggested. I will need to learn more about the package setup etc... for the classes folder.

I cannot see my new folder

I created a folder called "arg" in /var/tomcat4/webaps/
I created the WEB-INF folder inside ./arg
I copied and pasted the web.xml from /var/tomcat4/ROOT/WEB-INF/web.xml
- it was basic enough for what I think I am doing

when I browse to the location http://server:8180/arg I get an error saying:

"
type Status report
message /arg/
description The requested resource (/arg/) is not available.
"

Is there a missing step?

man I tell ya I don't have a problem with the coding... its all the symantecs of setting it up...

I really do appreciate your help.

Thanks, James
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Is there anything there to serve up? Did you place an index.html or index.jsp file there?

P.S. Don't feel frustrated. There is a lot to learn about setting up your first web app. Especially if you want to do it correctly. Have you found the Tomcat docs?
[ May 03, 2005: Message edited by: Bear Bibeault ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I have some simple pre-configured apps that you might want to take a look at.
They're not a substitute for reading and going through tutorials but sometime it helps to have a working example to reference.

http://simple.souther.us
Follow the directions on the site for deploying (should be about 5 to 7 mouse clicks if you have Tomcat up and running already).

Look at SimpleServlet and SimpleJSP first.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
Thank you so much

I will treasure these links, but I am still having problems.

1. I did put content into my "arg" folder index.html existed
2. After reading the docs... I saw that I actually needed to rstart Tomcat Imagine that! took me a while to find it... but... I found it

3. I have tried the SimpleServlet and SimpleJSP examples. All I get is a 404 error message. I have copied the .war files down. Restarted. The .war files unpacked, but when I browse to them http://webserver:8180/SimpleServlet and http://webserver:8180/SimpleJSP/index.html .... no dice
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Did you configure Tomcat to run on 8180?
By default it runs on 8080.

Can you hit the Tomcat welcome page?
http://localhost:8080
icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
ok...

I think I found a problem with SimpleServlet...

I checked the logs - yes logs are our friends - I am getting an error for SimpleServlet and SimpleJSP saying:

Parse error in application web.xml
org.xml.sax.SAXParseException: Element type "web-app" must be declared.

....

I got it to work...

Insight would be appreciated

...


the web.xml for both SimpleJSP and Simple Servant had a <web-app> block that was defined as:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

when this was present I got the errors

I changed it to
<web-app>

and it worked...

do you know what the difference is (other than <web-app> is simpler?)

Thanks again for all of your help

James
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Which version of Tomcat are you running?
icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
I am running 4.0.3-1

Also... I installed using an RPM which set up a default port of 8180. Whenever I try to use 8080 it times out...

It doesn't matter much to me... It is my developent server at home. I am just trying to get to a point where I can start developing cool stuff.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I did test those examples on 4.1.
Thanks for letting me know about the problem.
I'll put a note on my site letting people know there is an issue.

Out of curiosity, why are you using such an out of date version?
A lot of the stuff you'll find in tutorials these days (and a lot of things discussed in this forum) such as EL will not work in 4.0.
icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
here is the final version of a basic web.xml I got to work. I copied it from the /var/tomcat4/webaps/ROOT/WEB-INF/web.xml


<?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>
</web-app>


thanks,
your samples are a great start to what I want to do

James
icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
oh I picked 4 because that is just what I found...

I found a tutorial for tomcat and I get so lost as to what to get I just followed the instructions and it used RPM's

RPM's are my friend
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

The reason your web-app declaration failed was because that is a Servlet 2.4 declaration and Tomcat 4 supports 2.3. I suggest you upgeade to Tomcat 5 before proceeding any further.
icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
Great...

Do you know of any good tutorials to follow to reinstall for 5
icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
I really appreciate all the help you all have given.

I actually feel that I have a grasp on this stuff now. I feel that if someone gave me a simple assignment, I could realy do it.

thanks so much

James
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I think you'll find the non-rpm install to be trivial.

Download the tar.gz file.
Unpack it (tar -zxvf jakarta-tomcat...)
Set your JAVA_HOME environment variable (export JAVA_HOME=/usr/local/jdk1...)
CD to the {where ever you put tomcat}/bin directory.
Start Tomcat (./startup.sh)

Note: 5.5x requires Java5 unless you also get the "compat.tar.gz" file and unpack it from the same directory that unpacked tomcat into.
icredes
Greenhorn

Joined: May 03, 2005
Posts: 26
ok... we have 5.5.9 in the house

it is now time to rock and/or roll
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Congrats and welcome to j2ee, Javaranch
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
man! wish i knew about java ranch when i started out on servlets etc!!!

thanks a lot anyway to all the guys here!!!
 
wood burning stoves
 
subject: JSP Newbie needs help getting a clue!
 
Similar Threads
weblogic vs. tomcat vs. websphere
jsp vs servlets vs. beans
EJB vs Spring
JSP Vs SERVLETS
JSP Vs Servlets?JSP or Servlets