HELP : problème avec des .css et des .js qui passent en requête dans une servlet
salut;
j'essaie de suivre la procedure décrite dans le lien http://www.manu.e3b.org/Java/Tutoriels/J2EE/MVC.htm à fin de baser mon application web sur MVC dont voici les sources:
le brobleme constaté : quand je veux aller à la page cible (page2) les fichiers .css et .js (/design.css, ou truc.js, ... ) dont ils font partie, passent en requêtes dans la servlet de contrôle ce qui fait appel à des ressources non existante --> bizzar 8O
est ce à cause de l'objet RequestDispatcher qui fait la redirection ?
merci
WEB.XML:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 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">
<display-name>
test2</display-name>
<servlet>
<servlet-name>Start</servlet-name>
<servlet-class>contrôleur.Contrôleur</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Start</servlet-name>
<url-pattern>/Start/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>source</servlet-name>
<jsp-file>/source.html</jsp-file>
</servlet>
<servlet>
<servlet-name>cible</servlet-name>
<jsp-file>/cible.html</jsp-file>
</servlet>
<welcome-file-list>
<welcome-file>Start/source</welcome-file>
</welcome-file-list>
</web-app> |
CONTROLEUR:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
public class Contrôleur extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
String liaison = req.getPathInfo().substring(1);
System.out.println("LIAISON : "+liaison);
getServletContext().getNamedDispatcher(liaison).forward(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(req, resp);
}
} |
VUES:
page1:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Source</h1>
<hr/>
<form action="Start/cible" method="get">
<label for="verscible">Aller vers la cible :</label><input type="submit" value="Ok" id="verscible" />
</form>
</body>
</html> |
page2:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Exemple d'utilisation de CSS externe</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="screen" type="text/css" title="Design" href="design.css" />
</head>
<body>
<h1>je suis la cible</h1>
</body>
</html> |
ERREUR:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
LIAISON : source
LIAISON : cible
LIAISON : design.css
2 janv. 2009 18:42:45 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: "Servlet.service()" pour la servlet Start a généré une exception
java.lang.NullPointerException
at contrôleur.Contrôleur.doPost(Contrôleur.java:19)
at contrôleur.Contrôleur.doGet(Contrôleur.java:28)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619) |