Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to write web.xml deployment descripter

Status
Not open for further replies.

nkmb

Programmer
May 10, 2006
33
US
Hi All,

I am learning servlet programing.i am trying to do program which reqires three servlet classes and one html file.can anybody please help me writing web.xml.This is about my program.

SearchEngines.java. Servlet that takes a search string, number of results per page, and a search engine name, sending the query to that search engine. Illustrates manipulating response status codes. Requires the SearchSpec and ServletUtilities classes.

SearchSpec.java. Small class that encapsulates how to construct a search string for a particular search engine.

SearchEngines.html. Form that collects data for the search engine servlet.

ServletUtilities.java:It is Utilities class.




thanks inadvance
nkmb
 
Greetings nkmb,

Setting up your web.xml file should be fairly simple in this instance as you only have a single servlet. Allowing that $CATALINA_HOME points to your Tomcat installation, put the web.xml file in the $CATALINA_HOME/YourProgram/WEB-INF directory.

The web.xml file should look something like this
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"[URL unfurl="true"]http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">[/URL]

<web-app>
    <servlet>
      	<servlet-name>SearchEngines</servlet-name>
      	<servlet-class>SearchEngines</servlet-class>
      	<load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
       <servlet-name>SearchEngines</servlet-name>
       <url-pattern>/servlet/SearchEngines</url-pattern>
    </servlet-mapping>
    
    
    <welcome-file-list> 
        <welcome-file>SearchEngines.html</welcome-file>
    </welcome-file-list>     
</web-app>

A few notes: It is assumed that your java files are in the WEB-INF directory and that you are not using custom packages (if so, you will need to reflect those package names in the <servlet-class> section).

To access your servlet from your html file
Code:
<html>
...
<form action="servlet/SearchEngines">
..
</form>
</html>

It is important that you do not include the leading "/" in your action directive as the servlet is relative to your program's context.

Let us know if that works for you.

- Tim
 
Hi,

I did the same thing as u people told,still i am getting the error.


Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.

If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.


thanks
nkmb
 
and the URL you are trying to access is ...

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I had presumed you were using Tomcat. I do not know anything about Weblogic. Perhaps there is a forum in tek-tips about it?
 
Hi,

I am using the same URL as above mentioned.Now my problem has been solved,after changing my web.xml as of below


Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"[URL unfurl="true"]http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">[/URL]

<web-app>
    <servlet>
          <servlet-name>SearchEngines</servlet-name>
          <servlet-class>SearchEngines</servlet-class>
          <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
       <servlet-name>SearchEngines</servlet-name>
       <url-pattern>/SearchEngines</url-pattern>
    </servlet-mapping>
    
    
    <welcome-file-list> 
        <welcome-file>SearchEngines.html</welcome-file>
    </welcome-file-list>     
</web-app>



thanks
nkmb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top