17.08.2015, 18:48. Показов 4162. Ответов 2
| Java |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| public class CreateProductDTO {
@NotEmpty
private String name;
@NotEmpty
private String category;
@NotEmpty
private String description;
@NotEmpty
private String links;
@NotEmpty
private String country;
@NotNull
private int price;
public CreateProductDTO() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} |
|
| Java |
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
| @Controller
public class ProductCreateController {
private static final Logger log = Logger.getLogger(ProductCreateController.class);
@Autowired
private ProductService productService;
@Autowired
private SaleService saleService;
@Autowired
private UserService userService;
@RequestMapping(value = "/create", method = RequestMethod.GET)
public String createCourse(Model model, HttpSession session,
HttpServletRequest request) {
model.addAttribute("eMail", session.getAttribute("eMail"));
if (session.getAttribute("name") == null) {
return "redirect:/login";
} else {
model.addAttribute("eMail", session.getAttribute("eMail"));
User user = userService.findUserByName(session.getAttribute("name")
.toString());
CreateProductDTO createProductDTO = new CreateProductDTO();
model.addAttribute(createProductDTO);
return "create";
}
}
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String createCoursePost(Model model, HttpSession session,
HttpServletRequest request, @Valid CreateProductDTO createProductDTO,
BindingResult result) {
model.addAttribute("eMail", session.getAttribute("eMail"));
if (result.hasErrors()) {
System.out.println("hasErrors");
return "create";
} else {
model.addAttribute("eMail", session.getAttribute("eMail"));
Product product = new Product();
product.setName(createProductDTO.getName());
product.setDescription(createProductDTO.getDescription());
product.setLinks(createProductDTO.getLinks());
product.setCategory(createProductDTO.getCategory());
product.setCountry(createProductDTO.getCountry());
product.setPrice(createProductDTO.getPrice());
product = productService.createProduct(product);
return "redirect:/products";
}
} |
|
| HTML5 |
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
| <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="resources/css/style.css"/>
<style>
.error {
color: #ff0000;
}
.errorblock {
color: #000;
background-color: #ffEEEE;
border: 3px solid #ff0000;
padding: 8px;
margin: 16px;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>
Create a new Product
<div class="logout">
<span id="currentUserLogin">
${eMail}
</span>
<a href="logout.html">
<i class="icon-off"></i>
</a>
</div>
</h1>
</header>
<form:form commandName ="createProductDTO" method="POST">
<form:errors path="*" cssClass="errorblock" element="div" />
<fieldset>
<div class="control-group">
<label class="control-label">Name</label>
<div class="controls">
<form:input path="name" />
<form:errors path="name" cssClass="error" />
</div>
</div>
<div class="control-group">
<label class="control-label">Category</label>
<div class="controls">
<form:input path="category" />
<form:errors path="category" cssClass="error" />
</div>
</div>
<div class="control-group">
<label class="control-label">Description</label>
<div class="controls">
<form:input path="description" />
<form:errors path="description" cssClass="error" />
</div>
</div>
<div class="control-group">
<label class="control-label">Price</label>
<div class="controls">
<form:input path="price" />
<form:errors path="price" cssClass="error" />
</div>
</div>
<div class="control-group">
<label class="control-label">Country</label>
<div class="controls">
<form:input path="country" />
<form:errors path="country" cssClass="error" />
</div>
</div>
<div class="control-group">
<label class="control-label">Links</label>
<div class="controls">
<form:input path="links" />
<form:errors path="links" cssClass="error" />
</div>
</div>
<div class="form-actions">
<button id="createButton" name="createButton" class="btn btn-primary" type="submit">Create</button>
</div>
</fieldset>
</form:form>
<a class="btn" href="products.html">Cancel</a>
</div>
</body>
</html> |
|
| XML |
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
| <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.8.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>tck-utils-api</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.176</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.16</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.8.Final</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>javax.persistence</groupId> -->
<!-- <artifactId>persistence-api</artifactId> -->
<!-- <version>1.0</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency> |
|
| XML |
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
| <!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 version="2.5" 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_2_5.xsd">
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:application-context.xml
<!-- classpath:spring-security.xml -->
</param-value>
</context-param>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>SaleServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SaleServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Spring Security -->
<!-- <filter> -->
<!-- <filter-name>springSecurityFilterChain</filter-name> -->
<!-- <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> -->
<!-- </filter> -->
<!-- <filter-mapping> -->
<!-- <filter-name>springSecurityFilterChain</filter-name> -->
<!-- <url-pattern>/*</url-pattern> -->
<!-- </filter-mapping> -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app> |
|
Когда все поля заполняю, то товар добавляется. Если оставляю поле пустым, то вылетает ексепшн.
org.springframework.web.util.NestedServl etException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: javax.el.ExpressionFactory.newInstance() Ljavax/el/ExpressionFactory;
org.springframework.web.servlet.Dispatch erServlet.triggerAfterCompletionWithErro r(DispatcherServlet.java:1280)
org.springframework.web.servlet.Dispatch erServlet.doDispatch(DispatcherServlet.j ava:958)
org.springframework.web.servlet.Dispatch erServlet.doService(DispatcherServlet.ja va:870)
org.springframework.web.servlet.Framewor kServlet.processRequest(FrameworkServlet .java:961)
org.springframework.web.servlet.Framewor kServlet.doPost(FrameworkServlet.java:86 3)
javax.servlet.http.HttpServlet.service(H ttpServlet.java:637)
org.springframework.web.servlet.Framewor kServlet.service(FrameworkServlet.java:8 37)
javax.servlet.http.HttpServlet.service(H ttpServlet.java:717)
org.springframework.orm.hibernate4.suppo rt.OpenSessionInViewFilter.doFilterInter nal(OpenSessionInViewFilter.java:150)
org.springframework.web.filter.OncePerRe questFilter.doFilter(OncePerRequestFilte r.java:107)
использую el-api 2.2 c release последнюю.
В контейнере лежит 2.2