aspose file tools*
The moose likes Servlets and the fly likes Deploying servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Deploying servlet" Watch "Deploying servlet" New topic
Author

Deploying servlet

Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Hi there,

While learning about servlets, I have been deploying and testing my web apps locally using tomcat. I wanted to see how to put one of my apps (which works fine on my computer) on the web just for a test, so I got some web space with godaddy and have been trying to put it on. No joy. At first I thought it must be the database not connecting properly, so I played around with that for a while, then, just to see that the info from the client was getting through to my servlet, I wrote a test app with literally an html page saying, "this is the servlet test" with a button that can be clicked, supposedly to send a post request to the server and then I'd get back some data from the servlet (Just a string to be displayed saying "response from servlet").

I deployed the test app locally on my own computer using the tomcat container and it worked fine, so I put it up on the web to see if it would work. Unfortunately not.

I tested the client side stuff to make sure that an xmlhttprequest object doodah was created, and there were no problems there. The javascript function which sends the request off to the server finished. But I'm not getting a response from the servlet.

Naturally assuming that I couldn't possibly have done anything wrong I asked godaddy to check their systems and they said that 'Java was working fine on their systems'. I've checked that the file structure on the web is exactly the same as I've got it on my computer. And it is. I've mucked around with the DD to see if different fully qualified names for the servlet might work, but it didn't make any difference. Godaddy have said that checking to see that java is running fine on their systems is all they can do, so I'm wondering if anybody can give me a few ideas about what to try next.

Very grateful as always for any help.

Regards

Joe


OCPJP 85%
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30914
    
158

Joe Lemmer wrote:to see if it would work. Unfortunately not.

What does "work" mean? Did you get an error message? What happened that was different from what you expected.

As general advice, I recommend making your "Hello World" servlet even simpler to see what is going on. It sounds like yours uses AJAX. That's certainly not the simplest servlet you can make. The simplest one accepts get requests and writes out hello world. That way you can call it directly from the URL bar in the browser.

If this simpler servlet works, you are doing something wrong in the other example and can slowly build back up to it to see where things break. If not, it could be the deployment descriptor or a setting.

Post back here once you've tried this and someone can give more pointers on what to try on that path.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Excellent. Thanks for the reply Jeanne. I'll do that and post the results.
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
I've now made a very simple Hello World servlet and put it up in my webspace. I'm not sure if I'm using the right url, but I suppose I must be as the browser is finding the file, but instead of it running, a dialog box comes up and asks 'how do you want to open this file'.

So it's finding the file, but it's just a file.

I've used both the url:

www.mywebsite.com/myservlet

and

www.mywebsite.com/myservlet.class

and I get the same response.

Do you normally have to wait a while for an instance of the servlet to get running? I would phone godaddy again, but noone there knows anything about Java. Here's my servlet code anyway just in case I'm doing that wrong. Does anyone have any suggestions?



Regards

Joe
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
does this free webhosting service you mention about support Java in the first place ?
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Hi Dawn, thanks for your reply.

The web hosting isn't free and it has Java on it. I've checked with them twice and they've told me that it has.
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
Hi Joe..,

So, if you say that it works fine locally foryou, then it is just some tiny configuration problem.

Firstly, you dont have to add the .class to URL [unless you have some special mapping which I seriously doubt].
Can you show me the web.xml file for your application ? specifically the <servlet-class>, <servlet-name> and the <url-mapping> portions.

Dawn
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Hi Dawn

For my web app and the first test I did, I used a deployment descriptor, but for the v. simple servlet that Jeanne suggested, I didn't use a DD. Is it still necessary to use a DD even if you are typing the fully qualified url into the browser bar?

Thanks again

Joe
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
I've found a few answers to why things aren't working properly. I found this post, which explains a couple of things about the godaddy way of doing things.

If you like to deploy .war files, you might be disappointed to know that they only explode the war files at 0100 PST every day....

They also have a weird (to me) way of handling regular servlets.. if you have a standalone servlet, such as my DateServlet, you must put it in your WEB-INF/classes directory. Then to access it you must go to: www.yoursite.com/servlet/YourServlet. They don't seem to understand web.xml files (which allow for servlet mappings, in case you aren't familiar) unless you deploy the whole site (or subsite) as a war file.


So I forgot about the web.xml (because my test servlet is stand alone) and put in the url as suggested and made some progress, although this was in the form of an HTTP Status 500 error.

One of the errors was:



I found out is due to the fact that I compiled my .java files with a more up to date version of java than on godaddy. I use JDK 1.6. GoDaddy use 1.5.

The other error was:



not sure what that is, but I'm going to try downloading and compiling with JDK 1.5 and see what difference that makes.

Thanks Dawn and Jeanne for your help

Joe
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
No probs Joe.

However , you might want to note that you'll need a deployment descriptor [read web.xml] to map your servlets to URLs... however simple your servlet or app be.
And the answer to your last query [servletexception] is that - the webserver/servlet container, while handling the URL send by you [path, that is] could not find a matching servlet to initiate [because you didnt provide a mapping - coz, no web.xml]
Provide a web.xml for your app, place the classes in WEB-INF/classes, and yes, compile with JDK5 - Your app should be functional.

cheers,
Dawn.
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Awesomeness!!!

Thanks for the info Dawn. I really appreciate your help. :-)

Joe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deploying servlet