Bonjour,
je découvre spring au travers d'un tutoriel donné sur le site de spring :
http://www.springframework.org/docs/...p-by-step.html
Voilà l apartie 1 marche bien et mon controlleur affiche ma page Hello.jsp quand je demande hello.html.
Par contre l'étape visant à afficher la date me renvoie une erreur.
Voilà ce que j'ai fait :
web.xml:
testSpring-servlet.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 <?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>testSpring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>testSpring</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file> index.jsp </welcome-file> </welcome-file-list> </web-app>
include.jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!-- -Application context definition for "testSpring" DispatcherServlet. --> <beans> <bean id="testSpringController" class="controller.TestSpringController"/> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/hello.htm">testSpringController</prop> </props> </property> </bean> </beans>
index.jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <%@ page session="false"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
hello.jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <%@ include file="/jsp/include.jsp" %> <%-- Redirected because we can't set the welcome page to a virtual URL. --%> <c:redirect url="/hello.htm"/>
TestSpringController.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 <%@ include file="/jsp/include.jsp" %> <html> <head><title>Hello :: Spring Application</title></head> <body> <h1>Hello - Spring Application</h1> <p>Greetings, it is now <c:out value="${now}"/></p> </body> </html>
Voici l'erreur que j'obtiens :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package controller; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; public class TestSpringController implements Controller{ /** Logger for this class and subclasses */ protected final Log logger = LogFactory.getLog(getClass()); public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String now=(new java.util.Date()).toString(); logger.info("returning hello view with " + now); return new ModelAndView("/jsp/hello.jsp", "now", now); } }
Le plus bizarre c'est que dans mes log le controlleur renvoie bien la phrase :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 org.apache.jasper.JasperException: /jsp/hello.jsp(0,0) File "/jsp/include.jsp %> <html> <head><title>Hello :: Spring Application</title></head> <body> <h1>Hello - Spring Application</h1> <p>Greetings, it is now <c:out value=" not found at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:49) at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:383) at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:125) at org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:260) at org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:295) at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:333) ...
returning hello view with Wed Nov 15 11:13:50 CET 2006
la variable now existe donc bien là...
comment puis-je faire pour la récupérer dans ma jsp?
merci
Partager