• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HelloWorldServlet in Weblogic 6.0

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am using WebLogic 6.0 and placed the HTML file (index.html) in the DefaultWebApp_myserver and its working fine.I have also placed my servlets in DefaultWebAPP_myserver/WEB-INF/CLASSES/HelloWorldServlet. and tried to invoke the servlet from the browser http://localhost:7001/HelloWorldServlet... its giving error..."Error 404 not found"
Please anyone can help.
Thanks
Rajeev
 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to place this example servlet class file under the
C:\...\WEB-INF\classes\examples\servlets\HelloWorldServlet.class
because HelloWorldServlet.java is in the package examples.servlets
The next step is to prepare a web.xml file and put it in the
C:\...\WEB-INF directory with the proper <servlet-name>, <servlet-class>, and <servlet-mapping> elements.
 
Rajeev Bakhru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
Thanks for the reply
I think this will work ...but I am trying to port my applications from Tomcat to WebLogic.On tomcat all the servlets are running fine. So I was just trying to run the HellWorld Servlet or any other servlet from my existing application to run on WebLogic butits giving the same error.Is there ClassPath or Path we have to set. I did the setEnv command which sets the Path.
SO can u point what could be the problem.
Thanks
Rajeev
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose that your setEnv is right. For the time being, the only thing I can think of is to shut down your server and restart your server and run the HelloWorld again. If it does not work, then we have to go from the beginning step by step.
 
Rajeev Bakhru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It did'nt worked I tried by placing it in the exapmles/servltes/ sub directory and changed the web.xml and restarted the server but it did'nt worked .
Actually I installed the web logic evaluation version on Windows NT and started the server and it started properly do we have to do something else, like registering the servlet somewhere else other than web.xml
Rajeev
 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajeev,
If your WebLogic server starts up fine (and it seems to be because it served your html files), the container will take care of the classpaths. The Error 404 is most likely because of either incorrect Deployment Descriptors (the web.xml file), or incorrect placing of files.
I'm assuming you're deploying the servlets in un-jarred directories. Make sure all your files are in the correct structure. As JiaPei said, the servlet classes are in directories that match the package declarations. Finally, check to make sure the web.xml files are correct.
I use the default setEnv.cmd which probably looks like yours:
CLASSPATH=%JAVA_HOME%\lib\tools.jar\%WL_HOME%\lib\weblogic_sp.jar;%WL_HOME%\lib\weblogic.jar;%CLASSPATH%
and everything works fine.
Suppose you have a servlet MyServlet.class, with a package com.bakhru; statement.
MyServlet.class would be placed under ..\WEB-INF\classes\com\bakhru\MyServlet.class
(If there is no package statement, the it goes under ..\WEB-INF\classes\MyServlet.class.)
Now check your web.xml file.
For MyServlet.class it would resemble the following:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>MyServelt</servlet-name>
<servlet-class>com.bakhru.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet/*</url-pattern>
</servlet-mapping>
</web-app>
Hope this solves your problem.
JiaPei - Looks like you're ready for the exam!!
 
Rajeev Bakhru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe
I did the same way as u wrote step by step, but it did'nt worked i don't now why its not working.
The Classpath and path is also the same ...as default set by running setEnv command.
After that started the server with startWebLogic server command.Jsp working fine but servlets are not.
The other servlets of my application which were working on Tomcat, are also not working ...they are not in any package so i simply placed the class files in WEB-INF/classes/.. but was not successful in that also.

Lets hope u have any other suggestions
Thanks for the patience ...
Thanks
Rajeev
 
Joe McGuire
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm.. Your html and jsp works, but not your servlets.
If you haven't done so already, deploy the servlet from within the Administration Console and see if that works. Also, try jarring everything into a .war file and deploy that.
 
Rajeev Bakhru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe
I did the same way as u wrote step by step, but it did'nt worked i don't now why its not working.
The Classpath and path is also the same ...as default set by running setEnv command.
After that started the server with startWebLogic server command.Jsp working fine but servlets are not.
The other servlets of my application which were working on Tomcat, are also not working ...they are not in any package so i simply placed the class files in WEB-INF/classes/.. but was not successful in that also.

Lets hope u have any other suggestions
Thanks for the patience ...
Thanks
Rajeev
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajeev:
It is a frustrating feeling. I know exactly what it is. Let's try again. I have been listening to Joe's advice. He told you the right thing to do. Here is the setup of my classpath:
CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\lib\weblogic_sp.jar;%WL_HOME%\lib\weblogic.jar;%WL_HOME%\lib\xmlx.jar;C:\bea;
The web.xml file looks like:
<web-app>
<servlet>
<servlet-name>
HelloWorldServlet
</servlet-name>
<servlet-class>
examples.servlets.HelloWorldServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
HelloWorldServlet
</servlet-name>
<url-pattern>
helloWorld
</url-pattern>
</servlet-mapping>
</web-app>

examples.servlets.HelloWorldServlet is the full package name of your servlet class (use the example provided by the BEA WebLogic6.0 server distribution). Then, call your servlet from a Web browser
http://localhost:7001/helloWorld
Joe, There is still a long way for me to go for the exam. Hoping you feel ready for it. Best wishes.
 
Rajeev Bakhru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok i am going to try it again but one thing ...do we have to start the web logic default server or the web logic Examples server for it.(but in my view this is a stupid question after such a long discussion).
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajeev, It should be the WebLogic Default Server.
 
Rajeev Bakhru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Jen,
I did line by line ..with setting the classpath as u wrote ...but nothing worked ...so I have given up.
Its too much frustrating.
I checked on weblogic sites it says like this
"Receive a "Page cannot be displayed" or a "Error 404 - Not found" error when attempting to hit the server with a browser.
This can happen, if you're browser is set up to access all URLs through a proxy server. If the machine running WebLogic Server is not registered with the proxy server, you will receive a URL failure from your browser. To fix this, you can either configure your browser to either not use the proxy server or to not go through the proxy server accessing an address that begins with the name of the machine running WebLogic Server.
"
But I have no idea about this
 
Joe McGuire
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajeev, JiaPei, I am completely perplexed.
Don't give up just yet Rajeev. HTML and JSP pages work fine, right? I mean, you can stick a JSP file in the DefaultWebApp_myserver directory, and it serves it up okay. So your WebLogic server configuration and servlet engine must be okay. And you're not going through a proxy server. It's just gotta be something with those imported servlets. Have you tried just writing a really generic HelloWorld type servlet from scratch, and deploy it?
JiaPei - A colleague of mine used my guide and just passed the exam with an 86%. His advice was to pay close attention to JTA, EJBs, and *servlets*!
 
Joe McGuire
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If worse comes to worse Rajeev, you could email me the servlet class files (or better yet, the servlet class, source, and deployer files), and I could try to deploy them on my WLS6.0 workstation to see what happens.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajeev, I agree with Joe. Do not give up at this point. You have to resolve the problem in order to go on. I can't help wondering if the package statement in the HelloWorldServlet.java file is correct. And how did you compile the HelloWorldServlet.java file? I trust that you did them in the right way. I am asking these questions simply because something that should work does not work.

Joe, thanks for the tip. I have to work hard to keep up the pace with you guys.
 
Rajeev Bakhru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Jen, Joe
here is the setting of the classpath
:setEnv
set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\lib\weblogic_sp.jar;%WL_HOME%\lib\weblogic.jar;%WL_HOME%\lib\xmlx.jar;C:\bea;%CLASSPATH%
and details of web.xml file
<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 1.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>
HelloWorldServlet
</servlet-name>
<servlet-class>
examples.servlets.HelloWorldServlet
</servlet-class>
<servlet-mapping>
<servlet-name>
HelloWorldServlet
</servlet-name>
<url-pattern>
helloworld
</url-pattern>
</servlet-mapping>
</servlet>
</web-app>
I have compiled the servlet class by using javac -d c:\bea\wlserver6.0sp1\config\mydomain\applications\DefaultWebApp_myserever\web-inf\classes HelloWorldServlet.java
which worked fine.
So, is there any problem in all these steps followed.
Thanks
Rajeev
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajeev:
I am unable to pinpoint the problem. However, please try to make a minor change of DTD Web Application 1.2 in the statement:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 1.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
to DTD Web Application 2.2
Another question is:
Before you use javac -d ..... to compile your file, did you
DOS>cd c:\YourLocation\examples\servlets
DOS>set CLASSPATH=C:\YourLocation;%CLASSPATH%
DOS>javac -d ......
Is there a package statement as the first line in your HelloWorldServlet.java file?
Joe, what do you think. I can't think of anything else.
 
Joe McGuire
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I received Rajeev's HelloWorldServlet.class, HelloWorldServlet.java, and web.xml files, so I'm going to see if I can deploy it on my WLS6.0 environment...
 
Joe McGuire
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, the problem lay in the web.xml file!
Your original descriptor for the HelloWorldServlet was as follows:
<servlet>
<servlet-name>
HelloWorldServlet
</servlet-name>
<servlet-class>
examples.servlets.HelloWorldServlet
</servlet-class>
<servlet-mapping>
<servlet-name>
HelloWorldServlet
</servlet-name>
<url-pattern>
helloworld
</url-pattern>
</servlet-mapping>
</servlet>
But <servlet-mapping> should go outside the <servlet> tag. So you needed to close the <servlet> tag before starting your <servlet-mapping> tag. It should look like:
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>examples.servlets.HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>helloworld</url-pattern>
</servlet-mapping>
I placed the web.xml in: %\bea\wlserver6.0\config\mydomain\applications\DefaultWebApp_myserver\WEB-INF\web.xml
I placed your HelloWorldServlet.class in:
%\bea\wlserver6.0\config\mydomain\applications\DefaultWebApp_myserver\WEB-INF\classes\examples\servlets\HelloWorldServlet.class
Since your <url-pattern> is set to helloworld, you can now access the HelloWorldServlet from: http://127.0.0.1:7001/helloworld
Maybe TomCat was forgiving of this, but WebLogic isn't!
Let us know if it works out for you.
 
Rajeev Bakhru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe, Jen
Thanks a lot for the help ...at last it worked and as u pointed out Joe <servlet mapping> was the problem
I did this stupid mistake....and waisted 3 days for that ...but thats OK it worked
So now I have to try with my application servlets ...that they are working or not.
Once again thanks a lot
Rajeev

 
Joe McGuire
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad it worked out!
 
Rajeev Bakhru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe, Jen
One thing more do we have to make any changes for using Oracle as a backend database.
Is something to be added in the classpath.
Thanks
Rajeev
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BEA provides a variety of options for database access using the JDBC API specification. These options include two-tier JDBC drivers, incluidng WebLogic jDrivers for the Oracle. WebLogic jDriver for Oracle is included with the WebLogic Server distribution. This driver requires an Oracle client installation. Please see Installing and Using WebLogic jDriver for Oracle at http://edocs.bea.com/wls/docs60
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic