Bonjour tout le monde,
je reviens vers vous. Cette fois-ci il s'agit de l'erreur http 400.
Je suis entrain de vouloir inserer les donnés dans une table dans ma base de données. Cette table a une foreign key parmi ses colonnes. Elle a une relation manytoone avec la table dont elle possède la foreign key.
Voici les codes et la configuration
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 Quand je lance l'application,je reçois cette erreur: HTTP Status 400 - type Status report message description The request sent by the client was syntactically incorrect. Apache Tomcat/7.0.34
Code : Sélectionner tout - Visualiser dans une fenêtre à part Classe de service: SpettacoloServices.java du package starcinema.services
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package starcinema.services; import java.util.List; import javax.annotation.Resource; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import starcinema.model.Film; import starcinema.model.Spettacolo; /** * * @author simon */ @Service("spettacoloService") @Transactional public class SpettacoloServices { @Autowired @Resource(name="sessionFactory") private SessionFactory sessionFactory; Session session= null; public List<Spettacolo> getAllspettacolo(Integer idfilm) { session = sessionFactory.getCurrentSession(); Query query = session.createQuery("FROM Spettacolo WHERE idf=" +idfilm); return query.list(); } public List<Spettacolo> getAll() { session = sessionFactory.getCurrentSession(); Query query = session.createQuery("FROM Spettacolo"); return query.list(); } public Spettacolo get( Integer idspettacolo ) { session = sessionFactory.getCurrentSession(); Spettacolo spettacolo = (Spettacolo) session.get(Spettacolo.class, idspettacolo); return spettacolo; } public void addspettacolo(Integer idfilm, Spettacolo spettacolo) { session = sessionFactory.getCurrentSession(); Film existingFilm = (Film) session.get(Film.class, idfilm); spettacolo.setFilm(existingFilm); session.save(spettacolo); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part Controller
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
30
31
32
33
34 @Controller public class ControllerServlet { @Resource(name="spettacoloService") private SpettacoloServices spettacoloService; ..... ...... @RequestMapping(value = "admin.do", method=RequestMethod.GET) public String getAdd(@RequestParam("idfilm") Integer idfilm, Model model) { Spettacolo spettacolos = new Spettacolo(); spettacolos.setFilm(filmService.getfilm(idfilm)); model.addAttribute("spettacolo", spettacolos); return "admin"; } @RequestMapping(value = "listspettacolo.do") public String insertspettacolo(Model model) { spettacoloService.getAll(); return "listspettacolo"; } @RequestMapping(value = "insertspettacolo.do", method=RequestMethod.POST) public String insertspettacolo(@ModelAttribute() Spettacolo spettacolos, @RequestParam("idfilm") Integer idfilm, Model model) { spettacoloService.addspettacolo(idfilm, spettacolos); return "listspettacolo"; } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part Redirect.jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <%-- Views should be stored under the WEB-INF folder so that they are not accessible except through controller process. This JSP is here to provide a redirect to the dispatcher servlet but should be the only JSP outside of WEB-INF. --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <% response.sendRedirect("admin.do"); %>
Code : Sélectionner tout - Visualiser dans une fenêtre à part admin.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 <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Starcinema</title> </head> <body> <table border="0"> <tr><th>Titolo del film per qui si vuole inserire lo spettacolo</th></tr> <c:forEach var="film" items="${films}"> <tr> <td><a href="listspettacolo.do?idfilm=${idfilm}"><ul>${film.titolo}</ul></a></td> </tr> </c:forEach> </table> </body> </html>
Code : Sélectionner tout - Visualiser dans une fenêtre à part listspettacolo.jsp: dans ceci j'ai deux tables, une pour m'afficher les spettacles qui sont déjà dans la base de données et une autre pour me permettre d'y inserer les données
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title><img src="images/img/admin.jpg"/> ADMIN </title> </head> <body> <h1>Titolo Film: ${film.titolo}</h1> <br/> <table border="2"> <tr><th>Prezzo</th><th>Ora</th><th>Data</th><th>Sala</th></tr> <c:forEach var="spettacolo" items="${spettacolos}"> <tr> <td>${spettacolo.prezzo}</td> <td>${spettacolo.ore}</td> <td>${spettacolo.data}</td> <td>${spettacolo.numsala}</td> </tr> </c:forEach> </table> <br/> <h2>Add spettacolo</h2> <form name="spettacoloInsertForm" action="insertspettacolo.do" method="post"> <table border="2"> <tr> <td>Prezzo</td> <td><input type="text" name="prezzo" value=""</td> </tr> <tr> <td>Ora</td> <td><input type="text" name="ore" value=""</td> </tr> <tr> <td>Data</td> <td><input type="text" name="data" value=""</td> </tr> <tr> <td>Sala</td> <td><input type="text" name="numsala" value=""</td> </tr> </table> <input type="hidden" name="idfilm" value="${idfilm}"/> <input type="submit" value="ok"/> </form> </body> </html>
Code : Sélectionner tout - Visualiser dans une fenêtre à part web.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
25
26
27
28
29 <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>redirect.jsp</welcome-file> </welcome-file-list> </web-app>
Code : Sélectionner tout - Visualiser dans une fenêtre à part Application Context.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 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!--property name="dataSource"><ref local="dataSource"/></property--> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> </bean> </beans>
Code : Sélectionner tout - Visualiser dans une fenêtre à part Dispatcher.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
25
26
27 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <context:component-scan base-package="starcinema"/> <context:annotation-config/> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /> </beans>
J'utilise toujours netbeans, apache Tomcat 7.0.34 spring 3.1.1 et hibernate
3.2.5.
Pouriez-vous me donner encore un coup de main?
Je ne comprends pas pourquoi je dois avoir cette erreur pourtant me sembre ok.
Merci d'avance!
Partager