Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » log4j, Tomcat and WTP Server configuration?
log4j, Tomcat and WTP Server configuration? [message #210317] Wed, 12 March 2008 18:06 Go to next message
O  is currently offline O
Messages: 4
Registered: July 2009
Junior Member
I've configured log4j on tomcat 6.0.14 on Mac OSX as outlined at
http://tomcat.apache.org/tomcat-6.0-doc/logging.html.

I've created a dynamic web project (Eclipse 3.3) and integrated it with
the Maven2 plugin as outlined here:
http://www.devx.com/Java/Article/36785/0/page/1

The WTP server is configured such that "catalina.base" is created in the
"workspace" area.

My webapp builds, deploys & runs successfully on the WTP server instance.
However, I see no log files. The "catalina" output goes directly to the
Console view instead of the catalina.log file, or what I've configured in
the $catalina.home/lib/log4j.properties as configured per the first
article. And my log files as configured per my webapp's log4j.properties
file appears nowhere.

When I take the (maven plugin built) .war file and I deploy it onto the
tomcat installation, and start up tomcat via $catalina.home/bin/startup.sh
then I do see my log file. So, the configuration as far as my
log4j.properties, log4j.jar, commons-logging.jar inside of my war file is
correct. However, how do I get this to work with the WTP Server? Any idea,
what configuration piece I'm missing here?

I've tried to add the tomcat-juli-adapters.jar, tomcat-juli.jar &
log4j.properties files all located in $catalina.home to the CLASSPATH of
the WTP server via the "Run Dialog", to no avail.

Any help would be greatly appreciated.

Thanks.
Re: log4j, Tomcat and WTP Server configuration? [message #210325 is a reply to message #210317] Wed, 12 March 2008 19:59 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry Isaacs
Messages: 1308
Registered: July 2009
Senior Member
oalvarez wrote:
>
> I've configured log4j on tomcat 6.0.14 on Mac OSX as outlined at
> http://tomcat.apache.org/tomcat-6.0-doc/logging.html.
>
> I've created a dynamic web project (Eclipse 3.3) and integrated it with
> the Maven2 plugin as outlined here:
> http://www.devx.com/Java/Article/36785/0/page/1
>
> The WTP server is configured such that "catalina.base" is created in the
> "workspace" area.
>
> My webapp builds, deploys & runs successfully on the WTP server
> instance. However, I see no log files. The "catalina" output goes
> directly to the Console view instead of the catalina.log file, or what
> I've configured in the $catalina.home/lib/log4j.properties as configured
> per the first article. And my log files as configured per my webapp's
> log4j.properties file appears nowhere.
> When I take the (maven plugin built) .war file and I deploy it onto the
> tomcat installation, and start up tomcat via
> $catalina.home/bin/startup.sh then I do see my log file. So, the
> configuration as far as my log4j.properties, log4j.jar,
> commons-logging.jar inside of my war file is correct. However, how do I
> get this to work with the WTP Server? Any idea, what configuration piece
> I'm missing here?
>
> I've tried to add the tomcat-juli-adapters.jar, tomcat-juli.jar &
> log4j.properties files all located in $catalina.home to the CLASSPATH of
> the WTP server via the "Run Dialog", to no avail.
>
> Any help would be greatly appreciated.
>
> Thanks.
>
>
>

The Tomcat server launch configuration created in Eclipse will be
similar to that built and executed by Tomcat batch scripts, but not
necessarily identical. Duplicating the batch script behavior with
respect to logging is one area that hasn't been tackled yet, which I
hope to in WTP 3.0.

I don't have an answer off the top of my head, so until I have a chance
to dig further for Tomcat 6.0, you can inspect the batch scripts to see
what might be missing in the launch configuration. I did do this for
Tomcat 5.5 and the results are found here:

http://wiki.eclipse.org/WTP_Tomcat_FAQ#How_do_I_enable_the_J ULI_logging_in_a_Tomcat_5.5_Server_instance.3F

Cheers,
Larry
Re: log4j, Tomcat and WTP Server configuration? [message #210333 is a reply to message #210325] Wed, 12 March 2008 20:25 Go to previous messageGo to next message
O  is currently offline O
Messages: 4
Registered: July 2009
Junior Member
Thanks Larry.

I did see that (great) page for the JULI configuration, but I'm trying to
replace the JULI logging with log4j logging. I was hoping there'd be
something similar to those instructions but for log4j instead of JULI ;)

I've googled, but haven't found anything. Somebody has to have done this.



Larry Isaacs wrote:

> oalvarez wrote:
>>
>> I've configured log4j on tomcat 6.0.14 on Mac OSX as outlined at
>> http://tomcat.apache.org/tomcat-6.0-doc/logging.html.
>>
>> I've created a dynamic web project (Eclipse 3.3) and integrated it with
>> the Maven2 plugin as outlined here:
>> http://www.devx.com/Java/Article/36785/0/page/1
>>
>> The WTP server is configured such that "catalina.base" is created in the
>> "workspace" area.
>>
>> My webapp builds, deploys & runs successfully on the WTP server
>> instance. However, I see no log files. The "catalina" output goes
>> directly to the Console view instead of the catalina.log file, or what
>> I've configured in the $catalina.home/lib/log4j.properties as configured
>> per the first article. And my log files as configured per my webapp's
>> log4j.properties file appears nowhere.
>> When I take the (maven plugin built) .war file and I deploy it onto the
>> tomcat installation, and start up tomcat via
>> $catalina.home/bin/startup.sh then I do see my log file. So, the
>> configuration as far as my log4j.properties, log4j.jar,
>> commons-logging.jar inside of my war file is correct. However, how do I
>> get this to work with the WTP Server? Any idea, what configuration piece
>> I'm missing here?
>>
>> I've tried to add the tomcat-juli-adapters.jar, tomcat-juli.jar &
>> log4j.properties files all located in $catalina.home to the CLASSPATH of
>> the WTP server via the "Run Dialog", to no avail.
>>
>> Any help would be greatly appreciated.
>>
>> Thanks.
>>
>>
>>

> The Tomcat server launch configuration created in Eclipse will be
> similar to that built and executed by Tomcat batch scripts, but not
> necessarily identical. Duplicating the batch script behavior with
> respect to logging is one area that hasn't been tackled yet, which I
> hope to in WTP 3.0.

> I don't have an answer off the top of my head, so until I have a chance
> to dig further for Tomcat 6.0, you can inspect the batch scripts to see
> what might be missing in the launch configuration. I did do this for
> Tomcat 5.5 and the results are found here:

>
http://wiki.eclipse.org/WTP_Tomcat_FAQ#How_do_I_enable_the_J ULI_logging_in_a_Tomcat_5.5_Server_instance.3F

> Cheers,
> Larry
Re: log4j, Tomcat and WTP Server configuration? [message #210386 is a reply to message #210333] Fri, 14 March 2008 16:15 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry Isaacs
Messages: 1308
Registered: July 2009
Senior Member
I gave this a try on Windows XP using the logging.html document cited
below. For me, everything worked as expected, server and webapp
logging. Also, in a quick experiment, I got the server logging working
on Unbuntu Linux in the same fashion. No changes to the launch
configuration were required. Note that the example log4j.properties
uses "${catalina.home}", which will cause the Eclipse server to write to
the same log files as the Tomcat installation. Using "${catalina.base}"
would allow separate log files to be written.

Assuming this still isn't working for you, I wouldn't think being on Mac
OSX would make a difference. At this point, I don't know specifically
what might be different that is yielding a different result. I did not
attempt to do anything with commons-logging, but used log4j directly in
my simple test webapp. Perhaps you could test that. Also, it appears
that use of log4j by the server is independent of use in webapps. You
could try focusing on one or the other to try and see why it isn't
working. It's conceivable that when both are done, that common-logging
could interfere with both, but I'm just guessing.

Cheers,
Larry


oalvarez wrote:
>
> Thanks Larry.
>
> I did see that (great) page for the JULI configuration, but I'm trying
> to replace the JULI logging with log4j logging. I was hoping there'd be
> something similar to those instructions but for log4j instead of JULI ;)
>
> I've googled, but haven't found anything. Somebody has to have done this.
>
>
>
> Larry Isaacs wrote:
>
>> oalvarez wrote:
>>>
>>> I've configured log4j on tomcat 6.0.14 on Mac OSX as outlined at
>>> http://tomcat.apache.org/tomcat-6.0-doc/logging.html.
>>>
>>> I've created a dynamic web project (Eclipse 3.3) and integrated it
>>> with the Maven2 plugin as outlined here:
>>> http://www.devx.com/Java/Article/36785/0/page/1
>>>
>>> The WTP server is configured such that "catalina.base" is created in
>>> the "workspace" area.
>>>
>>> My webapp builds, deploys & runs successfully on the WTP server
>>> instance. However, I see no log files. The "catalina" output goes
>>> directly to the Console view instead of the catalina.log file, or
>>> what I've configured in the $catalina.home/lib/log4j.properties as
>>> configured per the first article. And my log files as configured per
>>> my webapp's log4j.properties file appears nowhere.
>>> When I take the (maven plugin built) .war file and I deploy it onto
>>> the tomcat installation, and start up tomcat via
>>> $catalina.home/bin/startup.sh then I do see my log file. So, the
>>> configuration as far as my log4j.properties, log4j.jar,
>>> commons-logging.jar inside of my war file is correct. However, how do
>>> I get this to work with the WTP Server? Any idea, what configuration
>>> piece I'm missing here?
>>>
>>> I've tried to add the tomcat-juli-adapters.jar, tomcat-juli.jar &
>>> log4j.properties files all located in $catalina.home to the CLASSPATH
>>> of the WTP server via the "Run Dialog", to no avail.
>>>
>>> Any help would be greatly appreciated.
>>>
>>> Thanks.
>>>
>>>
>>>
>
>> The Tomcat server launch configuration created in Eclipse will be
>> similar to that built and executed by Tomcat batch scripts, but not
>> necessarily identical. Duplicating the batch script behavior with
>> respect to logging is one area that hasn't been tackled yet, which I
>> hope to in WTP 3.0.
>
>> I don't have an answer off the top of my head, so until I have a
>> chance to dig further for Tomcat 6.0, you can inspect the batch
>> scripts to see what might be missing in the launch configuration. I
>> did do this for Tomcat 5.5 and the results are found here:
>
>>
> http://wiki.eclipse.org/WTP_Tomcat_FAQ#How_do_I_enable_the_J ULI_logging_in_a_Tomcat_5.5_Server_instance.3F
>
>
>> Cheers,
>> Larry
>
>
Re: log4j, Tomcat and WTP Server configuration? [message #213094 is a reply to message #210386] Tue, 29 April 2008 22:27 Go to previous messageGo to next message
Eclipse User
Originally posted by: jnadler.srcginc.com

Just another data point - I'm having this exact same problem. My app's
log4j.properties is ignored, but only when running Tomcat6 through wtp.
When running tomcat natively via tomcat/bin/startup.sh the exact same code
behaves as expected.

It's frustrating because however (mystery?) log4j is getting configured,
its root logger is debug and the volume of output going to the Console
window is overwhelming.

Not that I could possibly imagine how this would matter, but I'm on MacOS
also like the original poster.
Re: log4j, Tomcat and WTP Server configuration? [message #213178 is a reply to message #213094] Thu, 01 May 2008 13:28 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry Isaacs
Messages: 1308
Registered: July 2009
Senior Member
Jeff Nadler wrote:
> Just another data point - I'm having this exact same problem. My app's
> log4j.properties is ignored, but only when running Tomcat6 through wtp.
> When running tomcat natively via tomcat/bin/startup.sh the exact same
> code behaves as expected.
> It's frustrating because however (mystery?) log4j is getting configured,
> its root logger is debug and the volume of output going to the Console
> window is overwhelming.
> Not that I could possibly imagine how this would matter, but I'm on
> MacOS also like the original poster.
>

Are you using a packaged version of Tomcat or a binary download from
Apache? I'm not aware of anything in Apache's binary download for
Tomcat6 that would interfere with a webapp's use of log4j when run
inside or outside of Eclipse WTP. Some simple tests I did on WinXP
agrees with this.

Cheers,
Larry
Re: log4j, Tomcat and WTP Server configuration? [message #213320 is a reply to message #213178] Tue, 06 May 2008 17:31 Go to previous messageGo to next message
Vinay is currently offline Vinay
Messages: 36
Registered: July 2009
Member
Hello,

I see that the owner of this thread has successfully created the first web
application, however I am having great difficulties because the available
tutorial is more than three years old and the screen shots between the
tutorial and my current configuration do not match.

1. I am working on RHEL 4.6. And to avoid downloading different plugins I
downloaded the latest eclipse J2EE version. I am building my application
on this eclipse.

2. I have downloaded my tocat 6.0 and it is installed in ~/tomcat.
Independently I have created web application and ran them on this tomcat.

3. My eclipse and tomcat are in two different directories. If I create a
web app in my eclipse/workspace directory, how can that app run on tomcat,
where the applications run on "appbase" directory, which is generally
"webapps". How do I connect two directories together.

4. There are no compilation instructions given on the tutorial for web
application. My requirement is to compile through "ant" untility.

5. Following tutorial I could not specify "context root" directory. I
could not find that window where I could mention "context root".

Can you please help me with these initial steps in creating the
application or direct me to correct tutorial.

Thanks a lot. I am on a time crunch. Need help.

nagrik
Re: log4j, Tomcat and WTP Server configuration? [message #213330 is a reply to message #213320] Tue, 06 May 2008 18:36 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry Isaacs
Messages: 1308
Registered: July 2009
Senior Member
The answers below assume you are using Eclipse 3.3.

Cheers,
Larry

Nagrik wrote:
> Hello,
>
> I see that the owner of this thread has successfully created the first
> web application, however I am having great difficulties because the
> available tutorial is more than three years old and the screen shots
> between the tutorial and my current configuration do not match.
>
> 1. I am working on RHEL 4.6. And to avoid downloading different plugins
> I downloaded the latest eclipse J2EE version. I am building my
> application on this eclipse.
>
> 2. I have downloaded my tocat 6.0 and it is installed in ~/tomcat.
> Independently I have created web application and ran them on this tomcat.

If you haven't already done so, create a Tomcat target runtime and a
Tomcat server, i.e. select Window -> Preferences -> Server -> Installed
Runtimes and click Add. Enable the "Also create new local server"
checkbox. Expand the Apache node and select Apache Tomcat v6.0 and
click Next. Click Browse and navigate to the Tomcat installation to
fill in the "Tomcat installation directory". Adjust other fields as
desired and click Finish. Then refer to the WTP Tomcat FAQ
(http://wiki.eclipse.org/WTP_Tomcat_FAQ) to see details about the Tomcat
support in WTP. This includes how, by default, the Tomcat server
creates its own instance so your Tomcat installation isn't modified by WTP.

>
> 3. My eclipse and tomcat are in two different directories. If I create
> a web app in my eclipse/workspace directory, how can that app run on
> tomcat, where the applications run on "appbase" directory, which is
> generally "webapps". How do I connect two directories together.

This isn't necessary when using the Tomcat server within Eclipse. Open
the Servers view or switch to it in the JAVA EE Perspective.
Right-click on the Tomcat server and select "Add and Remove Projects" to
add a project to the server. When the server is "published", the
deployment of the webapp occurs. See the WTP Tomcat FAQ for details.

> 4. There are no compilation instructions given on the tutorial for web
> application. My requirement is to compile through "ant" untility.

You would have to create your own Ant build file for that. Eclipse has
it's own compiler which is capable of compiling as you type, or at least
when you pause. Building and deploying to WTP servers is handled for
you. To create a war for use outside of WTP, select File -> Export ->
Web -> WAR file and follow the wizard.

>
> 5. Following tutorial I could not specify "context root" directory. I
> could not find that window where I could mention "context root".

The Context Root can be specified in the Dynamic Web Project wizard when
creating the project or on the Web Project Settings page of the
project's Properties dialog.

>
> Can you please help me with these initial steps in creating the
> application or direct me to correct tutorial.
>
> Thanks a lot. I am on a time crunch. Need help.
>
> nagrik
>
>
Re: log4j, Tomcat and WTP Server configuration? [message #213334 is a reply to message #213330] Tue, 06 May 2008 23:03 Go to previous messageGo to next message
Vinay is currently offline Vinay
Messages: 36
Registered: July 2009
Member
Thanks Larry,

My server has been started from eclipse, and before starting it gave
following messages.

################
May 6, 2008 3:31:41 PM org.apache.tomcat.util.digester.SetPropertiesRule
begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting
property 'source' to 'org.eclipse.jst.jee.server:WTP-Tutorial1' did not
find a matching property.
May 6, 2008 3:31:41 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal
performance in production environments was not found on the
java.library.path:
/home/y/libexec/jdk1.6.0/jre/lib/i386/server:/home/y/libexec /jdk1.6.0/jre/lib/i386:/home/y/libexec/jdk1.6.0/jre/../lib/i 386:/home/y/libexec/jdk1.6.0/jre/lib/i386/client::/home/y/li bexec/jdk1.6.0/jre/lib/i386::/usr/lib/firefox-1.5.0.12:/usr/ lib/firefox-1.5.0.12:/usr/java/packages/lib/i386:/lib:/usr/l ib
May 6, 2008 3:31:41 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
May 6, 2008 3:31:41 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 605 ms
May 6, 2008 3:31:41 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 6, 2008 3:31:41 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.16
May 6, 2008 3:31:42 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
May 6, 2008 3:31:42 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
May 6, 2008 3:31:42 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/59 config=null
May 6, 2008 3:31:42 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1358 ms
May 6, 2008 3:32:28 PM org.apache.catalina.core.StandardServer await
WARNING: StandardServer.await: Invalid command '' received
################

In between I tried to unsuccessfully run my first SnoopServlet Web
application the browser gave following errors.

description: "The requested resourde (/SnoopServlet)is not available.

My directory structure looks like.

Servers
WTPTutorial
JavaResources:src
Libraries
Apache Tomcat v6.0
<There are bunch of .jar annotations.jar to tomcat-i18n-ja.jar>
EAR Libraries
<JRE System Library [jdk1.6.0] and it contains resources.jar to
sunjce_provider.jar>
Web App Libraries
build
classes <I do not see any java classes there>
org
eclipse
wtp
SnoopServlet.java
##############
This is the path I created when I was creating the web application. Does
org.eclipse.wtp.SnoopServlet.java has any significance.
##############

WebContent
< underthis there are META-INF and WEB-INF >
#####################
The web.xml looks like following.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<display-name>WTPTutorial2</display-name>
<servlet>
<servlet-name>Snoop Servlet</servlet-name>
<servlet-class>org.eclipse.wtp.tutorial.SnoopServlet</servlet-class >
</servlet>
<servlet-mapping>
<servlet-name>Snoop Servlet</servlet-name>
<url-pattern>/snoop/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
#####################

I also added my project by right clicking on the server perspective and it
added my project.

I opened up a fresh browser and typed localhost:8080/SnoopServlet, still
nothing came.

I am missing one crucial step. Can you tell me what it is.

thanks.

I do not see and class directory under WEB-INF
Larry Isaacs wrote:

> The answers below assume you are using Eclipse 3.3.

> Cheers,
> Larry

> Nagrik wrote:
>> Hello,
>>
>> I see that the owner of this thread has successfully created the first
>> web application, however I am having great difficulties because the
>> available tutorial is more than three years old and the screen shots
>> between the tutorial and my current configuration do not match.
>>
>> 1. I am working on RHEL 4.6. And to avoid downloading different plugins
>> I downloaded the latest eclipse J2EE version. I am building my
>> application on this eclipse.
>>
>> 2. I have downloaded my tocat 6.0 and it is installed in ~/tomcat.
>> Independently I have created web application and ran them on this tomcat.

> If you haven't already done so, create a Tomcat target runtime and a
> Tomcat server, i.e. select Window -> Preferences -> Server -> Installed
> Runtimes and click Add. Enable the "Also create new local server"
> checkbox. Expand the Apache node and select Apache Tomcat v6.0 and
> click Next. Click Browse and navigate to the Tomcat installation to
> fill in the "Tomcat installation directory". Adjust other fields as
> desired and click Finish. Then refer to the WTP Tomcat FAQ
> (http://wiki.eclipse.org/WTP_Tomcat_FAQ) to see details about the Tomcat
> support in WTP. This includes how, by default, the Tomcat server
> creates its own instance so your Tomcat installation isn't modified by WTP.

>>
>> 3. My eclipse and tomcat are in two different directories. If I create
>> a web app in my eclipse/workspace directory, how can that app run on
>> tomcat, where the applications run on "appbase" directory, which is
>> generally "webapps". How do I connect two directories together.

> This isn't necessary when using the Tomcat server within Eclipse. Open
> the Servers view or switch to it in the JAVA EE Perspective.
> Right-click on the Tomcat server and select "Add and Remove Projects" to
> add a project to the server. When the server is "published", the
> deployment of the webapp occurs. See the WTP Tomcat FAQ for details.

>> 4. There are no compilation instructions given on the tutorial for web
>> application. My requirement is to compile through "ant" untility.

> You would have to create your own Ant build file for that. Eclipse has
> it's own compiler which is capable of compiling as you type, or at least
> when you pause. Building and deploying to WTP servers is handled for
> you. To create a war for use outside of WTP, select File -> Export ->
> Web -> WAR file and follow the wizard.

>>
>> 5. Following tutorial I could not specify "context root" directory. I
>> could not find that window where I could mention "context root".

> The Context Root can be specified in the Dynamic Web Project wizard when
> creating the project or on the Web Project Settings page of the
> project's Properties dialog.

>>
>> Can you please help me with these initial steps in creating the
>> application or direct me to correct tutorial.
>>
>> Thanks a lot. I am on a time crunch. Need help.
>>
>> nagrik
>>
>>
Re: log4j, Tomcat and WTP Server configuration? [message #213342 is a reply to message #213334] Wed, 07 May 2008 00:27 Go to previous messageGo to next message
Vinay is currently offline Vinay
Messages: 36
Registered: July 2009
Member
Hello Larry,

I have my SnoopServlet.java under

WTP-Tutorial-1->Java Resources: src
->org.eclipse.wtp.tutorial->SnoopServlet.java
and the code looks like.

#######################
package org.eclipse.wtp.tutorial;

import java.io.IOException;

public class SnoopServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String userAgent = req.getHeader("user-agent");
String clientBrowser = "Not known!";
if( userAgent != null)
clientBrowser = userAgent;
req.setAttribute("client.browser",clientBrowser );
req.getRequestDispatcher("/showBrowser.jsp").forward(req,resp);
}
}
#######################

Now I see the build directory has multiple dirs inside and it also has
SnoopServlet.class inside

build->classes->org->eclipse->wtp->tutorial->SnoopServlet.class

So far so good.

The web.xml looks like under WebContent->WEB-INF->web.xml

##############
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<display-name>WTP-Tutorial-1</display-name>
<servlet>
<servlet-name>Snoop Servlet</servlet-name>
<servlet-class>org.eclipse.wtp.tutorial.SnoopServlet</servlet-class >
</servlet>
<servlet-mapping>
<servlet-name>Snoop Servlet</servlet-name>
<url-pattern>/snoop/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
##############


And lastly the showBrowser.jsp lies under WebContent and it looks like

###################
<html>
<head><title>Show Browser</title></head>
<body>
<table border="1">
<tr> <th>Header</th><th>Value</th>
</tr>
<tr>
<td>user-agent</td>
<td><%= request.getAttribute("client.browser")%></td>
</tr>
</table>
</body>
</html>

###################

The Server starts with no problem and displays the message

tomcat v6.0 Server at localhost Started synchronized

Still

1. The tutorial says you can open a web browser in eclipse. I can not.
2. When I type "localhost:8080/snoop (Not SnoopServlet), the browser says

description The requested resource (/snoop) is not available.

There is one step I am missing somewhere can someone help me.

nagrik
Re: log4j, Tomcat and WTP Server configuration? [message #213366 is a reply to message #213342] Wed, 07 May 2008 02:42 Go to previous messageGo to next message
Russell Bateman is currently offline Russell Bateman
Messages: 3199
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

Nagrik wrote:
[snip]
>
> The Server starts with no problem and displays the message
>
> tomcat v6.0 Server at localhost Started synchronized
>
> Still
> 1. The tutorial says you can open a web browser in eclipse. I can not.
> 2. When I type "localhost:8080/snoop (Not SnoopServlet), the browser says
> description The requested resource (/snoop) is not available.
>
> There is one step I am missing somewhere can someone help me.
>
> nagrik

Nagrik,

There are two browsers you can open. You can open Firefox, IE, etc.
external to Eclipse or you can let Eclipse open on for you. If your
project is set up correctly, in fact, Eclipse's own browser should open up.

I can't see your project, though I can divine its structure from your
deployment file. I have the following suggestions:

1. Attempt to launch your app via right-clicking on your first JSP/HTML
and choosing either Run as Server or Debug as Server. That will launch a
series of dialogs by which you can ensure that the Tomcat server will be
running on your webapp and it will then launch the browser. If your JSP
is coded correctly (or your HTML form), it should call your servlet.

2. In your deployment file (web.xml), I see that your servlet is named:

<servlet-name>Snoop Servlet</servlet-name>

That can't be right because a servlet is a class--a Java identifier--and
cannot have a space in the title. It's probably supposed to be:

<servlet-name>SnoopServlet</servlet-name>

Now, I know one can perform some name hocus pocus in web.xml, but I
think your problem is there.

3. I know you're in a hurry, but maybe you can read and compare my short
tutorial with your webapp (skip the bits on setting up Tomcat, Eclipse,
etc.). The webapp is fairly similar in structure and I had all the same
problems you're having.

http://www.windofkeltia.com/j2ee/wtp-tutorial.html

I hope this helps.

Russ Bateman
Re: log4j, Tomcat and WTP Server configuration? [message #213396 is a reply to message #213342] Wed, 07 May 2008 12:58 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry Isaacs
Messages: 1308
Registered: July 2009
Senior Member
Nagrik,

The URL to invoke a resource in a Web application will typically be
something like:

http://<host>:<port>/<context root>/<path to resource>

The "context root" of a Dynamic Web Project defaults to the same as the
name of the project. (Note: Certain characters that would cause problems
in the context root, such as spaces, will be altered.) Thus, the base
URL that would hit your Snoop Servlet would be:

http://localhost:8080/WTP-Tutorial-1/snoop/

I don't see any obvious problems other than the URL you are using.

Cheers,
Larry

Nagrik wrote:
> Hello Larry,
>
> I have my SnoopServlet.java under
>
> WTP-Tutorial-1->Java Resources: src
> ->org.eclipse.wtp.tutorial->SnoopServlet.java
> and the code looks like.
>
> #######################
> package org.eclipse.wtp.tutorial;
>
> import java.io.IOException;
>
> public class SnoopServlet extends HttpServlet {
> public void doGet(HttpServletRequest req, HttpServletResponse resp)
> throws ServletException, IOException {
> String userAgent = req.getHeader("user-agent");
> String clientBrowser = "Not known!";
> if( userAgent != null)
> clientBrowser = userAgent;
> req.setAttribute("client.browser",clientBrowser );
> req.getRequestDispatcher("/showBrowser.jsp").forward(req,resp);
> }
> }
> #######################
>
> Now I see the build directory has multiple dirs inside and it also has
> SnoopServlet.class inside
>
> build->classes->org->eclipse->wtp->tutorial->SnoopServlet.class
>
> So far so good.
>
> The web.xml looks like under WebContent->WEB-INF->web.xml
>
> ##############
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
> version="2.5">
> <display-name>WTP-Tutorial-1</display-name>
> <servlet>
> <servlet-name>Snoop Servlet</servlet-name>
> <servlet-class>org.eclipse.wtp.tutorial.SnoopServlet</servlet-class >
> </servlet>
> <servlet-mapping>
> <servlet-name>Snoop Servlet</servlet-name>
> <url-pattern>/snoop/*</url-pattern>
> </servlet-mapping>
> <welcome-file-list>
> <welcome-file>index.html</welcome-file>
> <welcome-file>index.htm</welcome-file>
> <welcome-file>index.jsp</welcome-file>
> <welcome-file>default.html</welcome-file>
> <welcome-file>default.htm</welcome-file>
> <welcome-file>default.jsp</welcome-file>
> </welcome-file-list>
> </web-app>
> ##############
>
>
> And lastly the showBrowser.jsp lies under WebContent and it looks like
>
> ###################
> <html>
> <head><title>Show Browser</title></head>
> <body>
> <table border="1">
> <tr> <th>Header</th><th>Value</th>
> </tr>
> <tr>
> <td>user-agent</td>
> <td><%= request.getAttribute("client.browser")%></td>
> </tr>
> </table>
> </body>
> </html>
>
> ###################
>
> The Server starts with no problem and displays the message
>
> tomcat v6.0 Server at localhost Started synchronized
>
> Still
> 1. The tutorial says you can open a web browser in eclipse. I can not.
> 2. When I type "localhost:8080/snoop (Not SnoopServlet), the browser says
> description The requested resource (/snoop) is not available.
>
> There is one step I am missing somewhere can someone help me.
>
> nagrik
>
>
>
Re: log4j, Tomcat and WTP Server configuration? [message #213403 is a reply to message #213366] Wed, 07 May 2008 13:07 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry Isaacs
Messages: 1308
Registered: July 2009
Senior Member
Windofkeltia wrote:
> Nagrik wrote:
> [snip]
>>
>> The Server starts with no problem and displays the message
>>
>> tomcat v6.0 Server at localhost Started synchronized
>>
>> Still
>> 1. The tutorial says you can open a web browser in eclipse. I can not.
>> 2. When I type "localhost:8080/snoop (Not SnoopServlet), the browser
>> says
>> description The requested resource (/snoop) is not available.
>>
>> There is one step I am missing somewhere can someone help me.
>>
>> nagrik
>
> Nagrik,
>
> There are two browsers you can open. You can open Firefox, IE, etc.
> external to Eclipse or you can let Eclipse open on for you. If your
> project is set up correctly, in fact, Eclipse's own browser should open up.
>
> I can't see your project, though I can divine its structure from your
> deployment file. I have the following suggestions:
>
> 1. Attempt to launch your app via right-clicking on your first JSP/HTML
> and choosing either Run as Server or Debug as Server. That will launch a
> series of dialogs by which you can ensure that the Tomcat server will be
> running on your webapp and it will then launch the browser. If your JSP
> is coded correctly (or your HTML form), it should call your servlet.
>
> 2. In your deployment file (web.xml), I see that your servlet is named:
>
> <servlet-name>Snoop Servlet</servlet-name>
>
> That can't be right because a servlet is a class--a Java identifier--and
> cannot have a space in the title. It's probably supposed to be:
>
> <servlet-name>SnoopServlet</servlet-name>
>
> Now, I know one can perform some name hocus pocus in web.xml, but I
> think your problem is there.
>
> 3. I know you're in a hurry, but maybe you can read and compare my short
> tutorial with your webapp (skip the bits on setting up Tomcat, Eclipse,
> etc.). The webapp is fairly similar in structure and I had all the same
> problems you're having.
>
> http://www.windofkeltia.com/j2ee/wtp-tutorial.html
>
> I hope this helps.
>
> Russ Bateman

In reference to item 2, I'm not aware of any problems with the servlet
name having a space. At least for this use case, I don't think any
objects would be instantiated using that name as it's identifier. It
would just be a text String stored in the servlet object created from
the web.xml.

Cheers,
Larry
Re: log4j, Tomcat and WTP Server configuration? [message #213411 is a reply to message #213396] Wed, 07 May 2008 18:56 Go to previous message
Vinay is currently offline Vinay
Messages: 36
Registered: July 2009
Member
Thank you Larry, thank you Windofkeltia. It worked. I was (as you pointed
out rightly) missing the Context Root.

nagrik
Previous Topic:Re: Graphical XML Schema Editor for 3.3.2?
Next Topic:How to place web files outside the application context?
Goto Forum:
  


Current Time: Thu Oct 02 02:21:20 GMT 2014

Powered by FUDForum. Page generated in 0.02648 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software