I get the impression you are a beginner at this. Reading the servlet spec would go a long way in understanding how the servlet container works. For the immediate problem:

1) Try to get SearchServlet in a package. ie: com.mycompany.myproject.SearchServlet This isn't strictly required for servlet classes, but excellent practice none the less. You will need packaged classes for any supporting classes you develop.

2) Map your servlet to a unique url of it's own and not to the url of existing JSPs. When you map your servlet to a url matching a jsp, the servlet is executed instead of the jsp per the mapping mechanism.

3) The action attribute of your form tag should be to the url you mapped your servlet to, not it's literal location at WEB-INF/classes/SearchServlet. Resources inside of WEB-INF are not directly accessible from the user and you'll get an error if you attempt it.

After the servlet does it's thing, it can forward the request to one of your jsps as necessary. The servlet spec can be found at http://www.jcp.org/en/jsr/detail?id=154

--David

Mark Whitby wrote:

Oops, that's a major typo on my part.  It is meant to say:

 <servlet>
   <servlet-name>SearchServlet</servlet-name>
   <servlet-class>SearchServlet</servlet-class>
 </servlet>
 <servlet-mapping>
   <servlet-name>SearchServlet</servlet-name>
   <url-pattern>/searchitem.jsp</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
   <servlet-name>SearchServlet</servlet-name>
   <url-pattern>/searchmatch.jsp</url-pattern>
 </servlet-mapping>


Now ironically enough now I've done this change my servlet is acting even more silly. When I type in searchmatch.jsp or searchitem.jsp into the address bar, it automatically sends me to the searchnone.jsp page.

So I'm guessing my code says I'm using forward and my words say I want to use redirect, is that correct? If so what's the best way to change my code so that when I go to searchmatch.jsp/searchitem.jsp I don't get automatically redirected to searchnone.jsp as I am doing, only when I've pressed the button and no items have been found that match the search parameter.

Mark

----- Original Message ----- From: "Caldarale, Charles R" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Monday, February 20, 2006 11:30 PM
Subject: RE: Fw: Servlet problem


From: Mark Whitby [mailto:[EMAIL PROTECTED]
Subject: Re: Fw: Servlet problem

If nothing is found then it redirects the user to
searchnone.jsp.  If an item or more than one item
is found then the page will redirect to itemlist.jsp
or matchlist.jsp


As a previous poster pointed out, there's a difference between redirect
(requiring a round trip to the client) and forward (a server-only
mechanism).  Which is it that you want to do?  (Your code says one
thing, your words another.)

I have the mapping twice yes, once for searchitem.jsp and once for
searchmatch.jsp, which both use the same servlet - SearchServlet.


 <servlet-mapping>
   <servlet-name>SearchServlet</servlet-name>
   <url-pattern>/searchmatch.jsp</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
   <servlet-name>SearchServlet</servlet-name>
   <url-pattern>/searchmatch.jsp</url-pattern>
 </servlet-mapping>

The above are your published mappings, copied and pasted from your
original message; these appear identical to me - both are for the
searchmatch.jsp pattern.

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to