You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by torechia <to...@attbi.com> on 2003/04/29 14:30:30 UTC
How to debug servlets under tomcat?
I am new to Tomcat and java servlets. I am running latest tomcat standalone on windows/xp and am having some problems doing transformations from xml to html in my java servlet. How can I debug this? I would like to step over each line of code and see what is happening. I have a copy of Visual J++, but am not sure how to compile and debug my servlets in this environment since I am not running IIS. Currently I am using ant to build and deploy my servlet. What is the best tool to debug servlets under tomcat and how can I get it started in the debugger under tomcat? Any help would be appreciated.
Re: How to debug servlets under tomcat?
Posted by "Mark W. Webb" <ma...@dolphtech.com>.
so all I need to do is place a file called log4j.properties in
WEB-INF/classes and tomcat is smart enough to see it and know what to do
with it? Wow! I did not know that . Cool.
Tim Funk wrote:
> I don't use a debugger. I use log4j. (Actually commons-logging)
>
> http://jakarta.apache.org/log4j/docs/manual.html
>
> Each webapp can be configured with its own log4j settings by dropping
> a file called log4j.properties into WEB-INF/classes
>
> Short term - its a PITA, long term it makes things much easier to fix.
>
> -Tim
>
> torechia wrote:
>
>> I am new to Tomcat and java servlets. I am running latest tomcat
>> standalone on windows/xp and am having some problems doing
>> transformations from xml to html in my java servlet. How can I
>> debug this? I would like to step over each line of code and see what
>> is happening. I have a copy of Visual J++, but am not sure how to
>> compile and debug my servlets in this environment since I am not
>> running IIS. Currently I am using ant to build and deploy my
>> servlet. What is the best tool to debug servlets under tomcat and
>> how can I get it started in the debugger under tomcat? Any help
>> would be appreciated.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: How to debug servlets under tomcat?
Posted by Tim Funk <fu...@joedog.org>.
I don't use a debugger. I use log4j. (Actually commons-logging)
http://jakarta.apache.org/log4j/docs/manual.html
Each webapp can be configured with its own log4j settings by dropping a file
called log4j.properties into WEB-INF/classes
Short term - its a PITA, long term it makes things much easier to fix.
-Tim
torechia wrote:
> I am new to Tomcat and java servlets. I am running latest tomcat standalone on windows/xp and am having some problems doing transformations from xml to html in my java servlet. How can I debug this? I would like to step over each line of code and see what is happening. I have a copy of Visual J++, but am not sure how to compile and debug my servlets in this environment since I am not running IIS. Currently I am using ant to build and deploy my servlet. What is the best tool to debug servlets under tomcat and how can I get it started in the debugger under tomcat? Any help would be appreciated.
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: How to debug servlets under tomcat?
Posted by Erik Price <ep...@ptc.com>.
torechia wrote:
> I am new to Tomcat and java servlets. I am running latest tomcat standalone on windows/xp and am having some problems doing transformations from xml to html in my java servlet. How can I debug this? I would like to step over each line of code and see what is happening.
I use unit testing (JUnit) and logging (Log4J). I'm sure there are some
debuggers for servlet stuff, but logging is seriously the most amazing
aid to programming and has helped me in so many ways. I just started
using it a little while ago.
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Forwarding from within a Servlet
Posted by Jan Behrens <ja...@diekleinedomain.de>.
Hi List,
I have a servlet that is supposed to controll the access of app-users on a
"per keyword" base. Certain jsp's in my app include that servlet on load and
pass a string specifying the calling pagename. The servlet then gets my
user-object out of the request-session and checks whether the particular user
is allowed to access or not. If he is, the servlet just writes a comment in to
the stream and thats it. If however the user is not allowed to access that
particular resource, I want to redirect the user to a different page within my
app. If the session expired and therefore no user-object could be found, I
would like to forward the user to a different page...
My problem is that I am quite new to servlets (have worked with jsp's only so
far) and I am not sure how to go about forwarding from within my servlet. I
have tried the following:
[snip]
if(DEBUG)out.println("<BR>logOutUser<BR>");
RequestDispatcher rd =
request.getRequestDispatcher(getPathToRoot(request) + TIMEOUT_URL);
try {
rd.include(request,response);
out.close();
}catch (Exception e) {
if(DEBUG)out.println("accessControll.accessDenied() <BR>"+e);
out.close();
}
[/snip]
getPathToRoot() basically takes the request.getHeader("referer") and extracts
the number of "/", minus those used in the hostname and returns a string
containing "../" for each "/" found and TIMEOUT_URL contains the complete path
to the resource from document-root.
The url build out of those is correct in itself, the RequestDispatcher however
doesn't forward to the right page but instead ignores all but the pagename.
It be very thankfull for any help & comment
Jan
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Forwarding from within a Servlet
Posted by Erik Price <ep...@ptc.com>.
Jan Behrens wrote:
> getPathToRoot() basically takes the request.getHeader("referer") and extracts
> the number of "/", minus those used in the hostname and returns a string
> containing "../" for each "/" found and TIMEOUT_URL contains the complete path
> to the resource from document-root.
> The url build out of those is correct in itself, the RequestDispatcher however
> doesn't forward to the right page but instead ignores all but the pagename.
3 things --
1) if you use a logger, have you logged the value returned from
getPathToRoot()? Make sure you do it from the actual URL (not just a
test URL) so you can confirm that the URL is what you expect it to be.
2) This is really just an extension of #1, that is that not every user
agent respects the "referer" header (in other words not every browser
will send it, esp. non-browser user agents). Confirm that this header
is indeed going out to your servlet.
3) You can get a resource relative to your context root by starting your
path with "/" (in the argument to getRequestDispatcher).
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Forwarding from within a Servlet
Posted by Jan Behrens <ja...@diekleinedomain.de>.
Hi List,
I have a servlet that is supposed to controll the access of app-users on a
"per keyword" base. Certain jsp's in my app include that servlet on load and
pass a string specifying the calling pagename. The servlet then gets my
user-object out of the request-session and checks whether the particular user
is allowed to access or not. If he is, the servlet just writes a comment in to
the stream and thats it. If however the user is not allowed to access that
particular resource, I want to redirect the user to a different page within my
app. If the session expired and therefore no user-object could be found, I
would like to forward the user to a different page...
My problem is that I am quite new to servlets (have worked with jsp's only so
far) and I am not sure how to go about forwarding from within my servlet. I
have tried the following:
[snip]
if(DEBUG)out.println("<BR>logOutUser<BR>");
RequestDispatcher rd =
request.getRequestDispatcher(getPathToRoot(request) + TIMEOUT_URL);
try {
rd.include(request,response);
out.close();
}catch (Exception e) {
if(DEBUG)out.println("accessControll.accessDenied() <BR>"+e);
out.close();
}
[/snip]
getPathToRoot() basically takes the request.getHeader("referer") and extracts
the number of "/", minus those used in the hostname and returns a string
containing "../" for each "/" found and TIMEOUT_URL contains the complete path
to the resource from document-root.
The url build out of those is correct in itself, the RequestDispatcher however
doesn't forward to the right page but instead ignores all but the pagename.
It be very thankfull for any help & comment
Jan
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: How to debug servlets under tomcat?
Posted by Tom Lyle <to...@limehouse.co.uk>.
this is a good little windows app that lets you step through servlet & jsp
code on any java app server, has a watch window and other stuff. Less time
consuming then using log statements
http://www.day.com/en/product/productline/unify/ide/dnlogin.html
Tom
> -----Original Message-----
> From: torechia [mailto:torechia@attbi.com]
> Sent: 29 April 2003 13:31
> To: Tomcat Users List
> Subject: How to debug servlets under tomcat?
>
>
> I am new to Tomcat and java servlets. I am running latest tomcat
> standalone on windows/xp and am having some problems doing
> transformations from xml to html in my java servlet. How can I
> debug this? I would like to step over each line of code and see
> what is happening. I have a copy of Visual J++, but am not sure
> how to compile and debug my servlets in this environment since I
> am not running IIS. Currently I am using ant to build and deploy
> my servlet. What is the best tool to debug servlets under
> tomcat and how can I get it started in the debugger under tomcat?
> Any help would be appreciated.
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org