PDA

Visualizza la versione completa : Servlet Java


Angelo1974
09-08-2003, 11:53
Salve a tutti! Ho una semplice servlet da richiamare... questo č il codice:

package byteGourmetServer;

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

import menu.generated.*;
import javax.xml.rpc.*;

/**
*

Title: </p>
*

Description: </p>
*

Copyright: Copyright (c) 2003</p>
*

Company: </p>
* @author not attributable
* @version 1.0
*/

public class ByteGourmetServer extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.processRequest( request, response );
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.processRequest( request, response );
}
private void processRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Enumeration e = request.getParameterNames();
PrintWriter out = response.getWriter();
ByteGourmetMenuBean bgBean = new ByteGourmetMenuBean();
while( e.hasMoreElements() ){
String name = ( String ) ( e.nextElement() );
String value = request.getParameter( name );
System.out.println( name + "\t" + value );
if( name.equals("restaurant") ){
if( value.equals("thaiPalace") ){
ThaiPalaceMenuServiceServiceLocator servizio = new ThaiPalaceMenuServiceServiceLocator();
ThaiPalaceMenuService porta = null;
try {
porta = servizio.getThaiPalaceMenuService();
}catch (ServiceException ex) {
System.err.println("Errore ServiceException"+ ex);
}
bgBean.setMenu( porta.getMenu() );
request.setAttribute( "menuBean", bgBean);
this.getServletConfig().getServletContext().getReq uestDispatcher("/menu.jsp").forward( request,response );
}
}
}
this.getServletConfig().getServletContext().getReq uestDispatcher("/welcome.jsp").forward( request,response );
}
//Clean up resources
public void destroy() {
}
}

Come si nota l'ho creata utilizzando il Borland JBuilder 8 enterprise.... questo č il file web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>AdminServlet</servlet-name>
<display-name>Axis Admin Servlet</display-name>
<servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>SOAPMonitorService</servlet-name>
<display-name>SOAP Monitor Service</display-name>
<servlet-class>org.apache.axis.monitor.SOAPMonitorService</servlet-class>
<init-param>
<param-name>SOAPMonitorPort</param-name>
<param-value>5001</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>bytegourmetserver</servlet-name>
<servlet-class>byteGourmetServer.ByteGourmetServer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SOAPMonitorService</servlet-name>
<url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>bytegourmetserver</servlet-name>
<url-pattern>/bytegourmetserver</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AdminServlet</servlet-name>
<url-pattern>/servlet/AdminServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
</web-app>

Come notate a me sembra che questo file sia scritto correttamente perņ, quando cerco di richiamare al servlet con l'url:
"http://localhost:8080/byteGourmetServer/ByteGourmetServer" mi esce un errore del tipo :
Help viewer error URL: Unable to open location: Document not found on server
Come mai?Qualcuno mi sa spiegare il motivo?Grazie a tutti:ciauz:

patrix03
12-08-2003, 17:13
ricontrollati il servlet-mapping... metti a posto l'url-pattern.
...col nome servlet magari..

Loading