 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Lan Guest
|
Posted: Tue May 25, 2004 11:01 am Post subject: [Tomcat 5-Servlet] Dispatcher che non funziona |
|
|
Ciao a tutti. Sto preparando un progetto universitario, un portale di
ecommerce. Sto sviluppando con una Servlet il Dispatcher che avrà il compito
di filtrare tutte le richieste e gestire gli accessi autorizzati. Il codice
funziona in genere, ma nel caso che serve a me NO!
Siccome tutte le richieste devono essere gestite dal Dispatcher ho bisogno
di configurare il file web.xml così:
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
In questo modo però Tomcat mi restituisce un mega errore
(javax.servlet.ServletException).
Il codice (di prova) del dispatcher interessato è questo:
package jshop;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.*;
import javax.servlet.RequestDispatcher;
public class DispatcherServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException,
IOException {
gotoPage("/index.jsp", request, response);
private void gotoPage(String page,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(page);
dispatcher.forward(request, response);
}
}
Suggerimenti?
Faccio notare che se nell'url-pattern metto un pattern senza asterisco il
Dispatcher funziona!!
Perchè non va con l'asterisco?
|
|
| Back to top |
|
 |
Dimitri De Franciscis Guest
|
Posted: Tue May 25, 2004 12:26 pm Post subject: Re: [Tomcat 5-Servlet] Dispatcher che non funziona |
|
|
Lan wrote:
| Quote: |
servlet-mapping
servlet-name>DispatcherServlet</servlet-name
url-pattern>/*</url-pattern
/servlet-mapping
|
Ma scusa, il package non lo mettiamo ?
<servlet-name>jshop.DispatcherServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
eh eh...
--
-- + Setaceous Pig + --
http://www.jroller.com/page/megadix/
|
|
| Back to top |
|
 |
Lan Guest
|
Posted: Tue May 25, 2004 3:46 pm Post subject: Re: [Tomcat 5-Servlet] Dispatcher che non funziona |
|
|
"Dimitri De Franciscis" <a@b.com> ha scritto nel messaggio
news:40B33B6F.2050601@b.com...
| Quote: | Lan wrote:
Ma scusa, il package non lo mettiamo ?
servlet-mapping
servlet-name>jshop.DispatcherServlet</servlet-name
url-pattern>/*</url-pattern
/servlet-mapping
eh eh...
|
No, non deve andare lì. Il file web.xml relativo a quella servlet è così
composto:
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>jshop.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Non è un problema di package perchè se sostituisco l'asterisco con un
percorso differente funziona tutto a meraviglia, ma a me serve su qualunque
richiesta venga fatta al server.
|
|
| Back to top |
|
 |
Lan Guest
|
Posted: Tue May 25, 2004 3:56 pm Post subject: Re: [Tomcat 5-Servlet] Dispatcher che non funziona |
|
|
"Dimitri De Franciscis" <a@b.com> ha scritto nel messaggio
news:c8vq71$fvf$1 (AT) tok (DOT) cu.mi.it...
| Quote: | Lan wrote:
Azz..è vero ! Hai provato a togliere lo slash davanti ?
Così:
...
url-pattern>*
...
|
si ho provato anche quello! Così non funziona, non mi trova la risorsa
(...
Guardando anche esempi online poi tutti mettono anche lo slash.
Non so più dove sbattere la testa, non capisco dov'è il problema!!
Aiutatemi vi prego! )
|
|
| Back to top |
|
 |
Dimitri De Franciscis Guest
|
Posted: Tue May 25, 2004 3:56 pm Post subject: Re: [Tomcat 5-Servlet] Dispatcher che non funziona |
|
|
Lan wrote:
| Quote: |
Non è un problema di package perchè se sostituisco l'asterisco con un
percorso differente funziona tutto a meraviglia, ma a me serve su qualunque
richiesta venga fatta al server.
|
Azz..è vero ! Hai provato a togliere lo slash davanti ?
Così:
....
<url-pattern>*</url-pattern>
....
--
-- + Setaceous Pig + --
http://www.jroller.com/page/megadix/
|
|
| Back to top |
|
 |
b.mauro Guest
|
Posted: Mon May 31, 2004 10:08 am Post subject: Re: [Tomcat 5-Servlet] Dispatcher che non funziona |
|
|
Lan wrote:
| Quote: | Ciao a tutti. Sto preparando un progetto universitario, un portale di
ecommerce. Sto sviluppando con una Servlet il Dispatcher che avrà il compito
di filtrare tutte le richieste e gestire gli accessi autorizzati. Il codice
funziona in genere, ma nel caso che serve a me NO!
Siccome tutte le richieste devono essere gestite dal Dispatcher ho bisogno
di configurare il file web.xml così:
servlet-mapping
servlet-name>DispatcherServlet</servlet-name
url-pattern>/*
/servlet-mapping
In questo modo però Tomcat mi restituisce un mega errore
(javax.servlet.ServletException).
Il codice (di prova) del dispatcher interessato è questo:
package jshop;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.*;
import javax.servlet.RequestDispatcher;
public class DispatcherServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException,
IOException {
gotoPage("/index.jsp", request, response);
private void gotoPage(String page,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(page);
dispatcher.forward(request, response);
}
}
Suggerimenti?
Faccio notare che se nell'url-pattern metto un pattern senza asterisco il
Dispatcher funziona!!
Perchè non va con l'asterisco?
|
Così a occhio direi che generi un loop in quanto il tuo dispatcher è
incaricato di rispondere a tutte le richieste (l'asterisco) coprese
quelle generate da se stesso! Nel momento in cui tu non metti
l'asterisco nell'URL mapping del dispatcher la richiesta verso index.jsp
non viene riprocessata dal dispatcher stesso e quindi funziona.
ciao
--
mauro
|
|
| Back to top |
|
 |
Alex 'Kazuma' Garbagnati Guest
|
Posted: Mon May 31, 2004 10:17 am Post subject: Re: [Tomcat 5-Servlet] Dispatcher che non funziona |
|
|
| Quote: | RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(page);
dispatcher.forward(request, response);
|
Stai dispatchando una richiesta...
prova a cambiare la creazione del dispatcher in questo modo:
RequestDispatcher dispatcher = request.getRequestDispatcher(page);
Regards,
Kazuma
--
Java User Group Milano - www.jugmilano.it
Alessandro "Kazuma" Garbagnati, kazuma(presso)jguru(punto)com
Tomcat & EJB FAQ Manager, http://www.jguru.com
|
|
| Back to top |
|
 |
Lan Guest
|
Posted: Mon Jun 28, 2004 4:20 am Post subject: Re: [Tomcat 5-Servlet] Dispatcher che non funziona |
|
|
"Lan" <nomail (AT) noprov (DOT) bo> ha scritto nel messaggio
news:CIFsc.239508$hc5.10273301 (AT) news3 (DOT) tin.it...
| Quote: | Ciao a tutti. Sto preparando un progetto universitario, un portale di
ecommerce. Sto sviluppando con una Servlet il Dispatcher che avrà il
compito
di filtrare tutte le richieste e gestire gli accessi autorizzati. Il
codice
funziona in genere, ma nel caso che serve a me NO!
Siccome tutte le richieste devono essere gestite dal Dispatcher ho bisogno
di configurare il file web.xml così:
servlet-mapping
servlet-name>DispatcherServlet</servlet-name
url-pattern>/*
/servlet-mapping
In questo modo però Tomcat mi restituisce un mega errore
(javax.servlet.ServletException).
Il codice (di prova) del dispatcher interessato è questo:
package jshop;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.*;
import javax.servlet.RequestDispatcher;
public class DispatcherServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException,
IOException {
gotoPage("/index.jsp", request, response);
private void gotoPage(String page,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(page);
dispatcher.forward(request, response);
}
}
Suggerimenti?
Faccio notare che se nell'url-pattern metto un pattern senza asterisco il
Dispatcher funziona!!
Perchè non va con l'asterisco?
|
Mi ero dimenticato di postare la soluzione. Ho risolto, insieme ad alcuni
del forum Sun, mappando anche le pagine jsp nel file web.xml. Purtroppo non
so farlo in modo dinamico (altrimenti bisognerebbe aggiungere a manina tutte
le jsp). Se qualcuno sa come farlo sarebbe una grande cosa!
Ciao
|
|
| Back to top |
|
 |
ingrid Guest
|
Posted: Mon Jul 05, 2004 2:01 pm Post subject: Re: [Tomcat 5-Servlet] Dispatcher che non funziona |
|
|
"Lan" <nomail (AT) noprov (DOT) bo> wrote
| Quote: | "Lan" <nomail (AT) noprov (DOT) bo> ha scritto nel messaggio
news:CIFsc.239508$hc5.10273301 (AT) news3 (DOT) tin.it...
Ciao a tutti. Sto preparando un progetto universitario, un portale di
ecommerce. Sto sviluppando con una Servlet il Dispatcher che avrà il
compito
di filtrare tutte le richieste e gestire gli accessi autorizzati. Il
codice
funziona in genere, ma nel caso che serve a me NO!
Siccome tutte le richieste devono essere gestite dal Dispatcher ho bisogno
di configurare il file web.xml così:
servlet-mapping
servlet-name>DispatcherServlet</servlet-name
url-pattern>/*
/servlet-mapping
In questo modo però Tomcat mi restituisce un mega errore
(javax.servlet.ServletException).
Il codice (di prova) del dispatcher interessato è questo:
package jshop;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.*;
import javax.servlet.RequestDispatcher;
public class DispatcherServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException,
IOException {
gotoPage("/index.jsp", request, response);
private void gotoPage(String page,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(page);
dispatcher.forward(request, response);
}
}
Suggerimenti?
Faccio notare che se nell'url-pattern metto un pattern senza asterisco il
Dispatcher funziona!!
Perchè non va con l'asterisco?
Mi ero dimenticato di postare la soluzione. Ho risolto, insieme ad alcuni
del forum Sun, mappando anche le pagine jsp nel file web.xml. Purtroppo non
so farlo in modo dinamico (altrimenti bisognerebbe aggiungere a manina tutte
le jsp). Se qualcuno sa come farlo sarebbe una grande cosa!
Ciao
|
Salve Lan,
sono Ingrid, e mi sono permessa di scriveri per chiederti un po di
aiuto per quanto riguarda JSP. Devo anche io per un progetto
lavorativo universitario fare un sito jsp (applicazione), un portale
quasi.
Io sono molto inesperta e non so da dove iniziare...o meglio ho le
idee confusissime.
Intatno ho iniziato installando il tomcat e tento di far girare
banalissimi file.java...mi potresti dare una mano per spiegarmi la
LOGICA con cui devo operare? Se mi potresti mandare anche qualche file
di esempio del tuo prgetto sarebbe perfetto...imparo molto
guardando...ti ringrazio in anticipo.
saluti ingrid
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|