jQuery in Action, 2nd edition*
The moose likes BEA/Weblogic and the fly likes Creating ServletContext in WebLogic! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "Creating ServletContext in WebLogic!" Watch "Creating ServletContext in WebLogic!" New topic
Author

Creating ServletContext in WebLogic!

Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
Hi Folks,
I just started using WebLogic. I am trying to use it based on my Tomcat experiece. In Tomcat, I can create a Context and put it in server.xml file to get it recognized by Tomcat. I am trying to do same thing in WebLogic but i couldnot figure it out. Basically i would like to do like this:
myContext-->WEB-INF-->classes-->testServlet
and access this testServlet like this:
http://localhost:7001/myContext/testServlet
my problem here is,
how can i create myContext and have WebLogic recognize it(in which file can i put in like i do it in server.xml file in Tomcat).
Thanks.


Himal
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
Create the myContext directory like you describe, and add a WEB-INF/web.xml file with servlet mappings.
In development mode (without -DProductionModeEnabled=true system property in start server command) you can put that directory in <domain-dir>/applications/myContext/... and it should get deployed with the context-root of myContext.
Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
i did the following: (i have weblogic 7 by the way)
i put the servlet class file(testServlet.class) in mydomain\applications\DefaultWebApp\WEB-INF\classes
and i write updated the web.xml in WEB-INF. then i started server and did following:
http://localhost:7001/DefaultWebApp/testServlet
this gave me Error 404--Not Found.
what's wrong?
And I still didn't get the idea of how and where i can define a list of Servlet Context so that the WebLogic recognize them.
i would appreciate if someone explain me these things.
thanks.
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
Not sure how your server is configured, but DefaultWebApp might be configured to be the default webapp (the one that maps to context-root of /). So try http://localhost:7001/testServlet
Otherwise, it should be at the context-root in the web.xml or the name of the webapp directory.
Also double check that you mapped the servlet to "testServlet" in web.xml.
WebLogic deploys WebApps, and you can't deploy just servlets by themselves. So there is no list of "servlet context" except in the web.xml of the webapp. To make a WebApp that uses servlets, you need the servlet mappings in web.xml. Then you just deploy the webapps and that's it.
The base URI that you use to access the webapp is called the context-root, and can be set in the web.xml.
That context-root can be overriden in application.xml if you include that webapp in a J2EE application (EAR).
If it's not set in either deployment descriptor, it defaults to the name of the webapp directory or war file (which is myContext in your case).
WebLogic also allows one webapp (or none) to be defined as the "default", which further overrides any context-root setting to "/". I don't suggest using this, as its clearer to set the context-root to / in one of the deployment descriptors (IMHO).
To deploy a webapp, the easiest way is to start the server in development mode and add the webapp to the <domaindir>/applications directory. The webapp can be either a war file or an "exploded war" directory (like what you have).
Another way to deploy a webapp is to put the war or exploded war anywhere outside that applications directory and use the server console to "configure a new webapp". Give it the path to the war or directory.
The console is always at
http://localhost:7001/console
(assuming your server started using port 7001 on the localhost machine). Use the administrator username/password to access it - you might have set this on install or needed to use it to start the server (it is often set to weblogic/weblogic).
You can use the server console to deploy, undeploy, or redeploy webapps or ejbs or applications.
As always, check the fine documentation at
http://e-docs.bea.com/ Stuff about building and deploying webapps is at http://edocs.bea.com/wls/docs70/webapp/index.html
[ October 24, 2002: Message edited by: Dave Landers ]
[ October 24, 2002: Message edited by: Dave Landers ]
Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
thanks Dave,
http://localhost:7001/testServer worked. i wonder how come, like in Tomcat, it did not require Servlet Context(DefaultWebApp in my case).
like i said earlier, my testServlet.class is in DefaultWebApp\WEB-INF\classes. Now i would like to create my own Context like DefaultWebApp, for example:
myContext\WEB-INF\classes. if i do this, where do i have to register this myContext so that weblogic knows. i saw a file "config.xml" in mydomain where the following lines of code are located:
<Application Deployed="true" Name="DefaultWebApp"
Path=".\applications" StagedTargets="" TwoPhase="false">
<WebAppComponent Name="DefaultWebApp" Targets="myserver" URI="DefaultWebApp"/>
</Application>
i am wondering if this is how i register my "myContext" too. i believe this file gets read as the WebLogic Server starts up.
you metnioned earlier this:
"In development mode (without -DProductionModeEnabled=true system property in start server command) you can put that directory in <domain-dir>/applications/myContext/... and it should get deployed with the context-root of myContext."
i am not sure how do i get in development mode and where and how i can set "DProductionModeEnabled". i am not even sure which mode i am in right now.
i would appreciate if you could help with these things. thanks for your help. i appreciate.
himal
Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
How do i create a ROOT DIRECTORY like DefaultWebApp in weblogic and register it so that weblogic recognize it? i want to deploy all my components in my own ROOT DIRECTORY instead of DefaultWebApp.
please educate me on this.
thanks.
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
I guess I don't understand how this hasn't been answered. Here goes....

If you still have a problem, how about being a bit more specific about what you've tried and what happened.
[ October 25, 2002: Message edited by: Dave Landers ]
 
GeeCON Prague 2014
 
subject: Creating ServletContext in WebLogic!