You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mark Whitby <ug...@cs.bham.ac.uk> on 2006/02/20 22:55:25 UTC
Servlet problem
Hi all,
Apologies for the stupidity of this email but I'm having a few servlet problems. I've created the following SearchServlet.java file, compiled it into a class file using Netbeans then copied the class file into my WEB-XML/classes file.
Now for testing the servlet is very limited but when I try to run the jsp page the page is redirected to http://localhost:8080/WEB-INF/classes/SearchServlet?itemvalue=type+search+criteria+here and not /searchnone.jsp as specified.
Can anyone tell me where I'm going wrong?
Mark
searchitem.jsp:
<table width="100%">
<tr>
<td>
<p class="subhead">Item Search Page</p>
<p>
Use this page to search through the different items that we stock. All searches are done by
key words. If using multiple words please use a comma after every different word.</i>.
</p>
<p>
<FORM ACTION="WEB-INF/classes/SearchServlet" METHOD="GET">
<INPUT TYPE="TEXT" NAME="itemvalue" SIZE="100" VALUE="type search criteria here"><br>
<INPUT TYPE="SUBMIT">
</FORM>
</p>
<p>
<a href="search.jsp">Return to the main search page</a>
</p>
</td>
</tr>
</table>
SearchServlet.java
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SearchServlet extends HttpServlet {
public void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String address = "/searchnone.jsp";
RequestDispatcher dispatcher = request.getRequestDispatcher(address);
dispatcher.forward(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}
}
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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 xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<!--
Specifies the first page that users will come to in the system
-->
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<!--
Specifies the error page that will occur for 404 errors
-->
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<!--
Database connection test
-->
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<servlet>
<servlet-name>SearchServlet</servlet-name>
<servlet-class>SearchServlet</servlet-class>
</servlet>
<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>
<!--
Specifies the security area within the system
-->
<security-constraint>
<web-resource-collection>
<web-resource-name>Secure Area</web-resource-name>
<url-pattern>/secure/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
</web-app>
RE: Servlet problem
Posted by GB Developer <gb...@globallyboundless.com>.
> Can anyone tell me where I'm going wrong?
what filip said, but also...
>From your servlet source code, make sure not to expect a server-side
operation, such as:
dispatcher.forward(request, response);
to result in a client-side 'refresh' to the 'specified' page
(searchnone.jsp, when you obtained the dispatcher).
dispatcher.forward() and .include() are performed as part of the original
request for /WEB-INF/classes/SearchServlet (which filip pointed out is
problematic)
Just from the way you phrased your question, I thought you were hoping to
see 'searchnone.jsp' on the address bar, and you won't get that with your
servlet as coded.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org