Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

more 11th hour stuff

Options
  • 27-03-2001 9:45pm
    #1
    Registered Users Posts: 6,661 ✭✭✭


    I can't get that bloody servlet to work! mad.gif

    It compiles (at last), but keeps giving a 500 (internal server error). I get the same thing from the example in the book, so I'm guessing I'm doing something wrong.

    How exactly do you test a sevlet, without having to actully run a webserver?


«1

Comments

  • Registered Users Posts: 1,023 ✭✭✭[CrimsonGhost]


    Yes you do. Or at least a 'servlet engine'. Not done this myself but
    http://internet.about.com/industry/internet/library/howto/htservlet.htm
    Should help you out.
    Hope that helps smile.gif


  • Registered Users Posts: 932 ✭✭✭yossarin


    You gotta run the startserver to test it
    also you gotta restart it if you recompile smile.gif -

    Common stuff:
    are you looking in
    http://127.0.0.1:8080/servlet/yourservletName
    to run the thing ? Does the startserver prog running in the background report any sort of error ?are you writing "servlets" instead of "servelt" in the above URL? are your class files in the "servlets" dir/properly ref'ed ?

    have you edited the servlets.properties file in dir WEB-INF ? you should add a line to the end of it eg
    yourservletName.code=yourservletName
    so that the servelt can find yourservletName.class

    sorry to go over this stuff but its just the sort of piddilin' cr*p that allways goes wrong.

    are you taking in parameters ? maybe its throwing an exzception involving them...


    [This message has been edited by yossarin (edited 28-03-2001).]


  • Registered Users Posts: 6,661 ✭✭✭Blitzkrieger


    That looks like exactly what I'm doing. frown.gif

    The book says to use http://localhost:8080/servlet/servletname

    but I'm guessing localhost and 127.0.0.1 are the same thing. I tried it both ways to make sure.

    I am taking in parameters but I tried a file where I wasn't to make sure that wasn't the problem.

    If it's some bloody typo that I'm too bleary eyed to spot.... mad.gif

    Thanks anyway.


  • Registered Users Posts: 932 ✭✭✭yossarin


    yeah, localhost == 127.0.0.1 useful if you've no network connection.

    Would you mind if i had a look at your code?
    I'm using the same version of jsdk that you are. Using my bat-sense, i predict that it IS some typo...

    incedently if you want to publish later on
    www.webappcareret.com do a poky but free servlet hosting service. they even support SSL.

    anyway, good luck...


  • Registered Users Posts: 6,661 ✭✭✭Blitzkrieger


    It won't bloody work frown.gif

    I've only 'till next wednesday to do it. I've a ton of programs based on it lined up as soon as I get this working but it won't work frown.gif

    HTTPGetServlet.html
    <font face="Verdana, Arial" size="2">
    <!-- Fig. 19.6: HTTPGetServlet.html -->
    <HTML>
    <HEAD>
    <TITLE>
    Servlet HTTP GET Example
    </TITLE>
    </HEAD>
    <BODY>
    <FORM
    ACTION="http://127.0.0.1:8080/servlet/HTTPGetServlet&quot;
    METHOD="GET">
    <P>Click the button to have the servlet send
    an HTML document</P>
    <INPUT TYPE="submit" VALUE="Get HTML Document">
    </FORM>
    </BODY>
    </HTML>
    [\QUOTE]

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

    public class HTTPGetServlet extends HttpServlet {
    public void doGet( HttpServletRequest request,
    HttpServletResponse response )
    throws ServletException, IOException
    {
    PrintWriter output;

    response.setContentType( "text/html" ); // content type
    output = response.getWriter(); // get writer

    // create and send HTML page to client
    StringBuffer buf = new StringBuffer();
    buf.append( "<HTML><HEAD><TITLE>\n" );
    buf.append( "A Simple Servlet Example\n" );
    buf.append( "</TITLE></HEAD><BODY>\n" );
    buf.append( "<H1>Welcome to Servlets!</H1>\n" );
    buf.append( "</BODY></HTML>" );
    output.println( buf.toString() );
    output.close(); // close PrintWriter stream
    }
    }
    </font>

    servlets.properties
    <font face="Verdana, Arial" size="2">
    # $Id: servlets.properties,v 1.2 1999/04/02 02:04:22 duncan Exp $

    # Define servlets here

    # <servletname>.code=<servletclass>
    # <servletname>.initparams=<name=value>,<name=value>

    # snoop.code=SnoopServlet
    # snoop.initparams=initarg1=foo,initarg2=bar
    jsp.code=com.sun.jsp.runtime.JspServlet

    HTTPGetServlet.code=HTTPGetServlet
    </font>

    I run the startserver.bat and launch the html file but nothing.

    I've got the .class file in the \jsdk2.1\webpages\web-inf\servlet directory. I've got the path set like the readme says : SET PATH=C:\jsdk2.1\bin;%PATH%

    I don't get it frown.gif


  • Advertisement
  • Registered Users Posts: 1,481 ✭✭✭satchmo


    That's wierd. Everything there seems to be right. Is the classpath set properly? If you're using the startserver.bat yossarin sent you then it's probably fine.

    What's happening when you click on the 'Get HTML Document' button? Do you get a 500, or a blank page? Do any exceptions appear in the startserver window?
    <font face="Verdana, Arial" size="2">I've got the path set like the readme says : SET PATH=C:\jsdk2.1\bin;%PATH%</font>
    I think that should be the JDK bin directory (c:\jdk1.3\bin or wherever your JDK is installed), not the JSDK \bin directory - there isn't one! Maybe that's the problem, as the JSDK needs to know the JDK path to run.


  • Registered Users Posts: 6,661 ✭✭✭Blitzkrieger


    the actual path is : SET PATH=C:\jsdk2.1\bin;C:\JDK1.2.1\BIN;%PATH%


    this is what I'm getting when I click on the 127.0.0.1:8080 link that the 500 error throws up :
    <font face="Verdana, Arial" size="2">
    Error: 500
    Internal Servlet Error:

    java.lang.NoSuchMethodError: javax.servlet.ServletContext: method getResource(Ljava/lang/String wink.gifLjava/net/URL; not found
    at com.sun.web.core.DefaultServlet.doGet(Compiled Code)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:499)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
    at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
    at com.sun.web.core.Context.handleRequest(Context.java:375)
    at com.sun.web.server.ConnectionHandler.run(Compiled Code)

    </font>


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    I copied the code and HTML you posted, and it compiled & ran fine confused.gif
    I've done my best to recreate that error, but no such luck. The only difference between your setup and mine that I can see is that you're using JDK 1.2.1, and I'm using 1.3. But the readme says the JSDK has been tested with JDK 1.2, so that's probably not the problem.

    Can you post the contents of your startserver.bat, and how you compile the servlet? It's got to be something to do with them.


  • Registered Users Posts: 932 ✭✭✭yossarin


    try somthing like :
    set CLASSPATH=,;d:\jsdk2.1\server.jar;d:\jsdk2.1\servlet.jar;d:\jsdk2.1\webpages\web-inf\servlets

    path=c:\jdk1.3\bin

    when setting your paths + compiling
    - ie point the classpath explicitly at each of the jar's + also at the servlet folder

    post your compilign instructions...?

    ps 'druid' ? i like it.
    I wanna be hight priest !

    pps i just looked at you path statments again - defo change them.

    [This message has been edited by yossarin (edited 02-04-2001).]


  • Registered Users Posts: 6,661 ✭✭✭Blitzkrieger


    Startsever.bat :
    <font face="Verdana, Arial" size="2">
    @echo off
    rem $Id: startup.bat,v 1.8 1999/04/09 19:50:34 duncan Exp $
    rem Startup batch file for servlet runner.

    rem This batch file written and tested under Windows NT
    rem Improvements to this file are welcome

    if "%CLASSPATH%" == "" goto noclasspath

    rem else
    set _CLASSPATH=%CLASSPATH%
    set CLASSPATH=server.jar;servlet.jar;classes;%CLASSPATH%
    goto next

    :noclasspath
    set _CLASSPATH=
    set CLASSPATH=server.jar;servlet.jar;classes
    goto next

    :next
    rem echo Using classpath: %CLASSPATH%
    start java com.sun.web.shell.Startup %1 %2 %3 %4 %5 %6 %7 %8 %9

    rem clean up classpath after
    set CLASSPATH=%_CLASSPATH%
    set _CLASSPATH=
    </font>

    That bit at the end looks a bit dodgy - like it's clearing the classpath again, but it's probably not run until I run the stopserver.bat

    I'll try using absolute addresses for the classpath instead of relative but I'm not hopeful.

    to compile, the book I'm using says just compile normally : javac HTTPGetServlet.java


    Thanks for all the help guys and keep it coming, please smile.gif



  • Advertisement
  • Registered Users Posts: 6,661 ✭✭✭Blitzkrieger


    Now it goes straight to the :
    <font face="Verdana, Arial" size="2">
    Error: 500
    Internal Servlet Error:

    java.lang.NoSuchMethodError: javax.servlet.ServletContext: method getResource(Ljava/lang/String wink.gifLjava/net/URL; not found
    at com.sun.web.core.DefaultServlet.doGet(Compiled Code)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:499)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
    at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
    at com.sun.web.core.Context.handleRequest(Context.java:375)
    at com.sun.web.server.ConnectionHandler.run(Compiled Code)

    </font>

    without going to the error page before it. I don't get it frown.gif


  • Registered Users Posts: 932 ✭✭✭yossarin


    I ran your code as well - it ran fine.

    its either not being compiled right or the servlet server is messed up.

    can you post your *.bat file (I'm assuming windows ?)
    hang in there...


  • Registered Users Posts: 6,661 ✭✭✭Blitzkrieger


    I posted the startserver.bat above. I changed the classpath from relative addresses to absolute and it takes me straight to the error page but that's about it frown.gif

    lol at the smiley poping up in the error page tho smile.gif


  • Registered Users Posts: 932 ✭✭✭yossarin


    it must be the compile. is the class file made ? + in the servlet dir?

    edit: sorry, you said above that it was...

    nuts, maybe its servlet then...
    where are you placing the java file when you compile ?

    pps how many posts do we have to do untill this becomes a hot topic ?

    [This message has been edited by yossarin (edited 03-04-2001).]


  • Registered Users Posts: 932 ✭✭✭yossarin


    lets make this post hot


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    I've mailed you the class file I compiled, so try it out and let us know if it runs or not.

    That startserver.bat is fine, it's the same one I use. It's got to be either the compilation or the servlet classes.


  • Registered Users Posts: 932 ✭✭✭yossarin


    Jazz are you a crazy 'poster' or a 'poser' ?


  • Registered Users Posts: 6,661 ✭✭✭Blitzkrieger


    lol - I don't have no life! I've been here years! biggrin.gif


    Thanks for that class file Jazz, but it didn't work frown.gif

    It must be just my computer frown.gif

    Suddenly I don't want to be a programmer anymore frown.gif



  • Registered Users Posts: 1,481 ✭✭✭satchmo


    Bloody hell, we're fast running out of options here! On the off-chance that there's a problem with your servlet .jar files, I'm going to send you the entire JSDK again. It's the same one as yossarin sent you, but just to be sure...

    If it doesn't work, post the entire contents of the DOS window that startserver puts up and we'll go from there. If everything goes according to plan, it should be:
    JSDK WebServer Version 2.1
    Loaded configuration from file:C:\Programming\JSDK2.1/default.cfg
    endpoint created: :8080
    com.sun.web.core.InvokerServlet: init
    HTTPGetServlet: init
    


  • Registered Users Posts: 932 ✭✭✭yossarin


    Its the engine then.
    try http://java.sun.com/products/servlet/archive.html

    and get the 2.1 engine.

    better still - use Jazz'z

    ...im a cool newbie - not just a normal one

    [This message has been edited by yossarin (edited 03-04-2001).]


  • Advertisement
  • Registered Users Posts: 1,481 ✭✭✭satchmo


    <font face="Verdana, Arial" size="2">Originally posted by yossarin:
    Jazz are you a crazy 'poster' or a 'poser' ?</font>
    What's that meant to mean 'yossarin'? Or should I say 'tosserin'?

    tongue.gif


  • Closed Accounts Posts: 345 ✭✭harVee


    i, was wondering if anyone could help.
    i have a final year project for tomorrow and it's all about doing 3D stuff with a dataglove.
    i've been nerding for days but no cigar...
    harVey


  • Registered Users Posts: 932 ✭✭✭yossarin


    thats not nice harVee

    that'll learn you for calling me a tosser

    allthough, throth be tolt i'm in much the same boat myself

    [This message has been edited by yossarin (edited 03-04-2001).]


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    It's for Thursday, not tomorrow. And it'll be ready. Oh yes, it will be ready...

    hows yours goin?


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    I apologize yoss, it was uncalled for.

    anyway, you're just jealous cause I've more stars than you wink.gif


  • Registered Users Posts: 932 ✭✭✭yossarin


    I am jealous.

    Messing with the GUI...
    which is fine enough but i want to get some mouse action going...


  • Registered Users Posts: 6,661 ✭✭✭Blitzkrieger


    This is what the startserver throws up :
    <font face="Verdana, Arial" size="2">
    JSDK WebServer Version 2.1
    Loaded configuration from file:C:\Programming\JSDK2.1/default.cfg
    endpoint created: :8080
    com.sun.web.core.InvokerServlet: </font>

    and then the IE window gives the 500 error. It shouldn't work, but should I try another browser? Surely the browser would have nothing to do with it.



  • Registered Users Posts: 1,481 ✭✭✭satchmo


    Well it can't hurt to try. And it sounds like the only thing left we haven't looked at is the browser...


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    Hang on, it would seem that the InvokerServlet isn't initialising properly, that's when the error is coming up. It's not even getting to your HTTPGetServlet. Did you try the jsdk2.1 I sent you?


  • Advertisement
  • Registered Users Posts: 6,661 ✭✭✭Blitzkrieger


    I had to spend all day yesterday getting documentation together, so I havn't had a chance to try it yet. Hopefully later today.


Advertisement