Question:
how can I view the error itself . not the code in java program?
aymoon1987
2008-05-08 05:37:38 UTC
I'm writing a java program
I'm requesting a url and it returns
"Server returned HTTP response code: 500 for URL:"
how can I view the complete error response like that
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
if it's a sql error or any error
Four answers:
Gary
2008-05-08 05:45:01 UTC
Well, any program you write in Java will undoubtedly throw exceptions at some point. To get the most of those exceptions, make you you write them to a log file or console. Also, you stack trace is a huge help in getting to source of a problem.



That said... you are seeing the error itself. You said you are requesting a URL and getting a 500 msg. Well, that's the message being returned by the server. There might possibly be some more embedded in the response you could pull out using the returned object... but heck, an internal server error is an internal server error.



--- EDIT UPDATE ---



I'm betting you won't be able to get that information in your Java application. Your question seems to indicate that you want to know what error the web server (or underlying app server) encountered. Unfortunately, those types of servers rarely return their underlying errors back to the requesting client.



You see, the server encountering the error has to report the problem somewhere. This will be in one of the servers error logs. Your Java application is simply a client of the server, not part of the server. In this respect, the server simply tells the client that something (but not what) has gone wrong.



While it is true that an ODBC connection is basically a client/server situation as well, the rules of the game are different. ODBC connections imply a much more involved relationship between client and server than a web connection does.



Imagine if every web server in the world passed the underlying problem back to the client? Every time Yahoo Answers "took a coffee break" you would be bombarded with more information than you need. What would your browser do with the information? You can't change the situation and you can't fix the problem.
2008-05-08 05:47:49 UTC
Try http://www.w3.org/Protocols/HTTP/HTRESP.html



500 means that the server encountered an unexpected condition which prevented it from fulfilling the request. If the server doesn't report the actual reason (and, in many cases, it just can't - Windows or Linux returned an error to the server), you can't "see" the error.



You could try looking at the server error log, though - use tail in a Linux box or Baretail in a Windows box - and watch the last error when you run that page. Then go back to the code and put some error trapping around that line, so you'll see exactly what the code was doing, and with what values in which variables, that caused the error. (Your SQL statement, if that's what the code is doing, could be a little different than you think it is. For debugging purposes, you can document.write() it.)
shiju u
2008-05-08 05:41:31 UTC
web servers return numbers as response to clients i.e if the response is ok it returns 200 and if a page is forbidden then it returns 401. you have to know the code
?
2016-05-28 19:04:24 UTC
Make sure you name the SAVED FILE the same as the CLASS. Otherwise you can't compile/run the program.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...