Web Hosting Talk







View Full Version : Java Servlettes


mbatalha
04-15-2003, 02:11 PM
My developer needs my server to be able to run java servlettes. Im running windows 2000 server. Can anyone point me in the right direction on what I need to install to have this done. Is it just the jdk that I need?

jb4mt
04-15-2003, 03:56 PM
Originally posted by mbatalha
My developer needs my server to be able to run java servlettes. Im running windows 2000 server. Can anyone point me in the right direction on what I need to install to have this done. Is it just the jdk that I need?

No, in addition to the JDK you need a "servlet engine". Check out Tomcat from:

http://jakarta.apache.org

It's free. We used Tomcat at my last job. It's from the folks at Apache, so it's good.

ilyash
04-15-2003, 06:20 PM
hes right... tomcat is awesome!

mbatalha
04-15-2003, 07:16 PM
im running a windows 2000 server with iis. I dont think I can use tomcat can I?

mbatalha
04-15-2003, 07:20 PM
i actually found a doc on how to install tomcat on iis. does anyone know where I can download it from?

jb4mt
04-16-2003, 03:21 PM
Originally posted by mbatalha
i actually found a doc on how to install tomcat on iis. does anyone know where I can download it from?

it? tomcat?

see my link above

ScottD
04-16-2003, 03:24 PM
I'd recommend taking a look at www.caucho.com. Resin is a great servlet engine, perhaps the fastest there is and they have documentation online describing how to integrate it with IIS.

Resin with IIS: http://www.caucho.com/resin/ref/cse-iis.xtp

jb4mt
04-16-2003, 03:29 PM
Originally posted by DizixCom
I'd recommend taking a look at www.caucho.com. Resin is a great servlet engine, perhaps the fastest there is and they have documentation online describing how to integrate it with IIS.

Resin with IIS: http://www.caucho.com/resin/ref/cse-iis.xtp

I've heard likewise. It costs though, unlike Tomcat, and cost may be a consideration for the OP?!

ScottD
04-16-2003, 03:32 PM
Good question. If cost is a factor, then Tomcat is plenty good enough. :)

mbatalha
04-21-2003, 10:42 AM
okay, thanks for all the replies. I have tomcat installed on iis. Looks like everything is working great.

I can run .jsp files now.

Now my developer is asking if my setup is correct because its not reading .java files. Is this a seperate setup. I looked in my configuration and I dont see anything or .java files to be read or anything at all.

Does anyone know anythin about this?

jb4mt
04-21-2003, 10:50 AM
Originally posted by mbatalha
okay, thanks for all the replies. I have tomcat installed on iis. Looks like everything is working great.

I can run .jsp files now.

Now my developer is asking if my setup is correct because its not reading .java files. Is this a seperate setup. I looked in my configuration and I dont see anything or .java files to be read or anything at all.

Does anyone know anythin about this?

The .java files would be the source code for servlets. Is he compiling them? (unlike .jsp files, .java files have to be explicitly compiled) Then the resultant .class files need to be in the correct location, which varies from application to application and is specified in configuration xml files.

rooshine
04-21-2003, 12:58 PM
If your developer is compiling the servlets, the resultant .class files will most likely go in a folder called "classes" which is located in the WEB-INF directory, but this can vary.

I'm not sure if this is what your developer is referring to about .java files, but...

Your web.xml file (also located in the WEB-INF directory) should have the following entry:

<mime-mapping>
<extension>java</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>

If these lines are missing, it might be the issue your developer is referring to. Just a warning, though: make a copy of your web.xml file if you make any changes.

Hope this helps.

mbatalha
04-21-2003, 02:51 PM
Im really a novice at setting up java servlets and tomcat.
I finally got the examples working inthe tomcat folder for the servlets. I actually had changed the jdk folder name and never updated the registry. Once i changed the javahome key in the registry it worked great.

Now I back to my developers setup not working. Does everything he has have to run under the webapps folder?

jb4mt
04-21-2003, 08:14 PM
Originally posted by mbatalha
Im really a novice at setting up java servlets and tomcat.
I finally got the examples working inthe tomcat folder for the servlets. I actually had changed the jdk folder name and never updated the registry. Once i changed the javahome key in the registry it worked great.

Now I back to my developers setup not working. Does everything he has have to run under the webapps folder?

I believe so but it's been 4 months since I worked with it much.

Here's a link to a page that has links to documentation for various versions on the left hand side:

http://jakarta.apache.org/tomcat/index.html

rooshine
04-21-2003, 08:56 PM
That depends on how you're configured. You can configure IIS to hand off .jsp files to Tomcat regardless of where they're located. I work with Apache, so I'm not sure how this is done on IIS, but I know it can be done.

As far as servlets, I believe they do have to go under webapps. There may be a way to change this, but I don't think so. Using servlet mapping, though, you can make it look like your servlets are virtually anywhere.

mbatalha
04-25-2003, 04:04 PM
does anyone know where i can find installation instructions for tomcat 4.124. Ive installed tomcat 3.23 successfully i think. Im still having problems with my developers work. I know his servelts work because they work locally on his laptop. When I put them under the webapps folder under tomcat it still doesnt run the servlet.

I think i have tomcat installed correcly and jdk because I can run the example jsp's and servelts fine. I thought maybe it was because the coding was incorrect somewhere and didnt know how the find the servlet.

Any help would be great. Even if you know of a book i can get that would guide you on how to setup a shared tomcat/iis server for hosting.

rooshine
04-25-2003, 04:27 PM
The installation help on apache's site is for 4.0, but I don't think it's changed:

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/RUNNING.txt

But it sounds as if tomcat is running fine. Did you create a myapps directory under webapps? In this directory, create the WEB-INF/classes directory. It's in the classes directory you'd place the compiled servlets.

Search for Tomcat on amazon and it wil pull up a selection of books. I can't make a recommendation, but some got good reviews.

mbatalha
04-25-2003, 05:37 PM
could i possibly have a problem with the installation of my JDK?


this is the error I am getting when I try to run the servlet.

HTTP 405 - Resource not allowed
Internet Information Services

rooshine
04-25-2003, 09:01 PM
I don't think it's your JDK. Are you trying to send POST data to the servlet? I know there are a couple of issues with IIS sending POST data to non-dynamic pages. It might not recognize your servlet correctly. Sorry, IIS really isn't my specialty. For troubleshooting, try changing POST to GET.

mbatalha
04-25-2003, 11:45 PM
i was trying to post. but i think the examples are post to. they work fine.

rooshine
04-26-2003, 12:44 AM
Hmmm, the message is being generated by IIS, not tomcat. Sounds like IIS isn't recognizing your servlet as a valid resource. But I wouldn't no where to begin to configure IIS. Try this posting here: saloon.javaranch.com (http://saloon.javaranch.com)

It's a java board. Likely someone there uses IIS with Tomcat and can help.

mbatalha
05-01-2003, 04:17 PM
well Ive made some progress. I know I have tomcat 4.124 configured correctly and jsdk1.41 installed correctly now.

I even got my developers code to work.

Not the way i wanted to but until i find out why this is how im going to do it. This is what i did and maybe from this bit of information you guys canhelp me out.

I copied the examples folder over under webapps under a new name. so i kept the structure but renamed the folder. Then i deleted all the servlets and jsp files.

then i added all my developers servlets to the servlets folder and jsp to the jsp folder.

i ran the servlet from port 8080 and everything runs now.

i must not be creating a file somewhere that tell tomcat where the servlets are but since the examples structure already had this it new to go to the webapps classes folder.

Im not sure if its in the .war file or in the .xml file or actually a server config but it works this way.

Can anyone shed some light on the situation?

jb4mt
05-01-2003, 04:47 PM
it's the web.xml file under the WEB-INF subfolder inside the folder for the application

mbatalha
05-01-2003, 04:48 PM
what about it?

rooshine
05-01-2003, 09:17 PM
If your developer correctly packaged your app in the .war file, then you should be able to place this under the webbapps directory. Restart tomcat and the correct directory structure will automatically be created. You would then access the app like: yourdomain.com:8080/yourapp/yourservlet

In this case, replace yourapp with the name of the war file.

Have you tried this? If it doesn't work, then it could be your web.xml file, and we will try to help you with that.

mbatalha
05-01-2003, 10:28 PM
im using tomcat 4.124 and i dont see any war files anywhere. the only thing i see are web.xml files. im in the tomcat manager and im trying to create a new directory. is this what im supposed to be doing? is my developer supposed to be creating this web.xml file?

rooshine
05-01-2003, 11:09 PM
A war file is just a convenient way to package an application. If your developer didn't give it to you, then you wouldn't have it. For future projects, you can ask your developer to package the application this way as it will make installation almost fool proof (almost.)

Create a new directory in the webapps folder with the name you want for your application. In this directory, create a directory called WEB-INF. In this directory, create a file called web.xml. You can copy the web.xml file from the tomcat examples and just make some changes. This is a very basic web.xml file, but it should do:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>Name</servlet-name>
<servlet-class>Class</servlet-class>
</servlet>

<servlet>
<servlet-name>NameTwo</servlet-name>
<servlet-class>Class</servlet-class>
</servlet>

</web-app>


This is a very simple web.xml file, but it should work. Just replace the <servlete-name> values with the name you want to access the servlet by, and the <servlet-class> with the name of the Class.

With this web.xml, you would reach your servlet like this:

yourdomain.com:8080/yourapp/servlet/yourservlet

If you don't want to have to use the word servlet, you can add a servlet mapping element to the web.xml. That looks like this:

<servlet-mapping>
<servlet-name>Name</servlet-name>
<url-pattern>/newURL</url-pattern>
</servlet-mapping>

Now you would access your servlet like this:
yourdomain.com:8080/yourapp/newURL

You can use wildcard characters in the <url-pattern> if you want.

After you do this, create a directory in WEB-INF called classes, and place the compiled servlets and any other classes here. If they are in packages, you will need to create the directory structure to match the package names. If your servlets are in a .jar file, create a directory under WEB-INF called lib and place them here. You do not need to create the directories for packages in this case.

Hope this helps.


Ross