0
votes

So I asked this question: 404 Not Found Error on GET/POST Request from Client to Java Servlet

And I figured it out, however, the output I am getting on the client side is a bunch of gibberish. But when I look closer, the gibberish resembles my java servlet file, so I'm getting something right; it's just formatted weird.

Anyone have any clue as to why this is happening? Am I missing something in my code or could it be something to do with the server I am utilizing?

The output should only have the following text:

some text boiii

Yet this is what I see:

����1J ( )*+, -./0*12*34 56 5789:()VCodeLineNumberTableLocalVariableTablethisLMyTestServlet;doPostR(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)Vrequest'Ljavax/servlet/http/HttpServletRequest;response(Ljavax/servlet/http/HttpServletResponse;Exceptions;<doGettextLjava/lang/String;pwLjava/io/PrintWriter; SourceFileMyTestServlet.java!=>?$MyTestServlet doGet function Invoked@ABsome text boiii text/htmlCBUTF-8DBEFGHBIjava/lang/Exception MyTestServletjavax/servlet/http/HttpServletjavax/servlet/ServletExceptionjava/io/IOException&javax/servlet/http/HttpServletResponsegetOutputStream%()Ljavax/servlet/ServletOutputStream;!javax/servlet/ServletOutputStreamprintln(Ljava/lang/String;)VsetContentTypesetCharacterEncodinggetWriter()Ljava/io/PrintWriter;java/io/PrintWriterwriteclose!/��I+,��#$ !�6,��N,�, � ,�:-�� �N�14 *+,-.&/,01442564#"#&$%666&'

PS: All the source code/details is in the other question. Thanks!

1
What's the url you're using that gives that back? It looks like you're getting a binary .class file instead of the output from running a servlet.Always Learning
@SteveFrancisco $.get("WEB-INF\\classes\\MyTestServlet.class", function(responseText) {...Ibrahim
ok, you're just loading the .class file into your browser, not calling a servlet. If you've set up a servlet on your server you should be accessing it through the servlet alias. That tells the server to run the code on the server with any parameters you provide. All you've done here is ask the server to give you the .class file, which it did.Always Learning

1 Answers

1
votes
  1. Download a Tomcat from tomcat.apache.org, and extract it to c:\tomcat\
  2. rename your index.html to index1.jsp
  3. change .get("/ServletTest4/ServerTest")
  4. change

    ServletTest /ServletTest

  5. build your project again.

  6. find the webapps folder under c:\tomcat\

  7. copy ServletTest4 folder from ..\target\ and paste it into the webapps\

  8. go bin\ under c:\tomcat

  9. start tomcat by click startup.bat

  10. browser: http://localhost:8080/ServletTest4/index1.jsp