Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to deploy a war file on Weblogic Server 7.0??

843840Nov 3 2002 — edited Nov 3 2002
Hello Everyone
I am trying to deploy a servlet on Weblogic Server 7.0 as a WAR file. Can anyone of u plz tell me the steps required to do that. I am posting this question on EJb forum and not on servlets coz this is not a servlet problem, rather this is something which is related to J2EE, ie how to deploy a war file on J2EE Server.

This is how i have done it, but this is not working---


(1) First i created a directory structure for the web application according to J2EE Specification.

C:\Work\
myServletWAR\
META-INF\
WEB-INF\
classes\
HelloServlet.class
web.xml

i.e within work directory, there is a dic called myServletWAR which is my application directory which contains 2 sub directories viz META-INF which contains the mainifest file being generated by the jar utility. the second directory in the myServletWAR application dir is WEB-INF, which contains one file called web.xml for servlet mapping and one directory classes which contains HelloServlet.class

(2) I used following command for creating war file from myServletWAR director(i.e from my web application's directory).
jar -cvf TestServletWAR.war .

This creates the TestServletWAR.war file in myServletWAR dir.


Here is how my Servlet and web.xml looks like...



----------------------------------------------------------
Servlet code
----------------------------------------------------------

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServlet extends HttpServlet
{
public void doPost ( HttpServletRequest req, HttpServletResponse res )
throws IOException, ServletException
{
doGet( req, res );
}

public void doGet ( HttpServletRequest req, HttpServletResponse res )
throws IOException, ServletException
{
res.setContentType( "text/html" ); // Can also use "text/plain" or others.
PrintWriter out = res.getWriter();

// Get the requestor's IP address (See JavaDocs to see how to get other info):
String addr = req.getRemoteAddr();

// Create output (the response):
out.println( "<HTML><HEAD><TITLE>HelloServlet in myServletWAR</TITLE></HEAD>" );
out.println( "<BODY><H1 ALIGN=\"CENTER\">" );
out.println( "Hello " + addr + ", from HelloServlet in myServletWAR!" );
out.println( "</H1></BODY></HTML>" );
out.close();
}
}


************************Servlet Ends Here **************************

----------------------------------------------------------
web.xml
---------------------------------------------------------- <!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>

<display-name>myServletWAR, a first Web Application</display-name>
<description>
This is a simple web application containing a single servlet
of the "Hello, World" variety.
</description>

<servlet>
<servlet-name>myHello</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>myHello</servlet-name>
<url-pattern>/myHello</url-pattern>
</servlet-mapping>

</web-app>

****************************web.xml file ends here********************

After deploying the TestServletWAR.war file on the weblogic 7.0, i tried to execute the servlet from the browser by the following URL

http://localhost:7001/myServletWAR/myHello

I am getting the HTTP 404 Error, which is an indication that weblogic was unable to find the resourse, which it was requested for. Can anybody plz tell me what i m doing worng?? do i need to use weblogic related xml file (i.e weblogic.xml) also along with web.xml. If yes, then what all i need to include that. I m not very sure. A sample weblogic.xml file for this HelloWorld example will help me a lot.
Looking forward for your help

Thanx in advance
Nisha
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 1 2002
Added on Nov 3 2002
1 comment
258 views