Jump to content

[Solved] Problem With Java Servlets


guardmed

Recommended Posts

Hello,

I have an account on Jhonny with java enabled.

JSP is working fine but Servlets just won't work.

 

I tried the most basic class I could find:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res)
  throws ServletException, IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();

out.println("<HTML>");
out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
out.println("<BODY>");
out.println("<H1>Hello World</H1>");
out.println("Today is: " + (new java.util.Date().toString()) );
out.println("</BODY></HTML>");
  } // doGet
} // HelloWorld

And compiled it.

 

I uploaded it to /public_html/WebContent/WEB-INF/classes and added the needed info to web.xml. I could not reach the servlet HelloWorld.

I uploaded it to /public_html/WEB-INF/classes and added the needed info to web.xml. I still could not reach the servlet HelloWorld.

 

I tried any combination I could think of in order to get this servlet to work, but nothing did the trick.

If anyone knows or has been able to activate the servlets, here are my three questions:

  1. Where did you put the compiled servlet class?
  2. Where did you put the "web.xml" (I know, in the WEB-INF, but there are two)?
  3. How did you do the servlet mapping in the "web.xml" (using the .class in the path or not)?
  4. What URL did you use to reach the servlet (with starting from the <name>.heliohost.org/)?

I tried any combination I could think of but nothing did the trick.

 

Thank

Link to comment
Share on other sites

If anyone knows or has been able to activate the servlets, here are my three questions:

Since you prefaced your questions with this condition I figured you wanted someone to respond who knows what they are talking about. I'll be the first to admit that I have no clue what I'm talking about so I abstained from commenting.

Where did you put the compiled servlet class?

No clue.

Where did you put the "web.xml" (I know, in the WEB-INF, but there are two)?

Don't know the answer to that either.

How did you do the servlet mapping in the "web.xml" (using the .class in the path or not)?

Beats me.

What URL did you use to reach the servlet (with starting from the .heliohost.org/)? I tried any combination I could think of but nothing did the trick.

Probably guardmed.heliohost.org/appname, but that's just a guess.

Anyone? Anything? Please?

Ah yes, now I qualify! How about this: If you can create me a .war file of your servlet and upload it to /home/guardmed I can play around with it and see if I can get it to work. No promises though, because I've never done any of this stuff either. Just let me know once it's uploaded.

Link to comment
Share on other sites

Thank you Krydos

 

I deleted all files from the account (jsp, class, xml, images. everything).

I uploaded HelloWorld.war.

The reason I did not do so in the first place is because of the following thread - http://www.helionet.org/index/topic/11272-deploying-war-file-java-application/page__hl__%2Bservlet+%2Bfile__fromsearch__1

 

 

Information about this war file:

  1. The website name is HelloWorld - in my system I actually use http://localhost:8080/HelloWorld/
    So I assume on the heliohost server it should be something like guardmed.heliohost.org/HelloWorld
  2. There is one JSP in the war, it's named Hello.jsp.
    This is actually reachable using the url http://guardmed.heliohost.org/HelloWorld/Hello.jsp
  3. There is one servlet in the war, it's named HelloWorld.
    Could not reach it any way
  4. There is a web.xml with the following needed information

    1. The welcome page is defined to be Hello.jsp, meaning that the url http://guardmed.heliohost.org/HelloWorld/ should go directly to http://guardmed.heliohost.org/HelloWorld/Hello.jsp
      For some reason right now this doesn't happen. It does happen on my system.
    2. There is a servlet mapping for HelloWorld to /HelloWorld.
      So I would expect http://guardmed.heliohost.org/HelloWorld/HelloWorld to go the servlet (but it doesn't).

It's interesting to see that the tomcat does open the war, because it opens the jsp when called directly.

 

Any help would be appreciated

Link to comment
Share on other sites

I tried using my local installation of tomcat and run this war.

It works on my machine.

I still don't understand why neither the servlet nor the welcome page definition work on the heliohost server.

Link to comment
Share on other sites

How does this look? http://guardmed.heliohost.org/HelloWorld/ Sorry for the delay; was busy with the holidays.

 

Thank you Krydos, this is impressive.

I would like to know how you were able to make it work (as the "HelloWorld" project isn't really the goal I'm trying to achieve).

 

One thing is a mystery to me.

The welcome page works - it goes to Hello.jps like it should - http://guardmed.heliohost.org/HelloWorld/

The servlet works - like Shineryuu showed in the screenshot - http://guardmed.heliohost.org/HelloWorld/HelloWorld

Directly accessing the jsp no longer works - it originally worked, but now no longer does - http://guardmed.heliohost.org/HelloWorld/Hello.jsp

I don't understand how using the direct url no longer works. More interesting, the jsp can be reached using the welcome page, but not directly. So I'm guessing something probably changed with the url address. I wonder what.

 

Thank you and happy holidays, whichever they may be.

Link to comment
Share on other sites

I would like to know how you were able to make it work (as the "HelloWorld" project isn't really the goal I'm trying to achieve).

I made it work because I have more access as an administrator than a regular user does.

 

While it is possible to deploy WAR files on HelioHost, it would require additional configuration by the administrators.

I'm considering setting up an automated way for Johnny accounts with java enabled to deploy their own .war files, but for now users can just drop their .war in their home directory like /home/username/Project.war and I can deploy it for them.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...