Skip to content

Commit ecc6625

Browse files
committed
Add form tag example
1 parent 09d9cf2 commit ecc6625

5 files changed

Lines changed: 42 additions & 42 deletions

File tree

‎spring-mvc-xml/src/main/java/org/baeldung/spring/ClientWebConfig.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
@Configuration
99
public class ClientWebConfig extends WebMvcConfigurerAdapter {
1010

11-
public ClientWebConfig() {
12-
super();
13-
}
11+
public ClientWebConfig() {
12+
super();
13+
}
1414

15-
// API
15+
// API
1616

1717
}
Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package org.baeldung.spring;
22

3+
import java.util.Locale;
4+
import java.util.ResourceBundle;
5+
6+
import org.springframework.context.MessageSource;
37
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.support.MessageSourceResourceBundle;
9+
import org.springframework.context.support.ResourceBundleMessageSource;
410
import org.springframework.web.servlet.ViewResolver;
511
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
612
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@@ -11,27 +17,40 @@
1117
//@Configuration
1218
public class ClientWebConfigJava extends WebMvcConfigurerAdapter {
1319

14-
public ClientWebConfigJava() {
15-
super();
16-
}
20+
public ClientWebConfigJava() {
21+
super();
22+
}
23+
24+
@Bean
25+
public MessageSource messageSource() {
26+
27+
final ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
28+
ms.setBasenames("messages");
29+
return ms;
30+
}
31+
32+
@Bean
33+
public ResourceBundle getBeanResourceBundle() {
1734

18-
// API
35+
final Locale locale = Locale.getDefault();
36+
return new MessageSourceResourceBundle(messageSource(), locale);
37+
}
1938

20-
@Override
21-
public void addViewControllers(final ViewControllerRegistry registry) {
22-
super.addViewControllers(registry);
39+
@Override
40+
public void addViewControllers(final ViewControllerRegistry registry) {
41+
super.addViewControllers(registry);
2342

24-
registry.addViewController("/sample.html");
25-
}
43+
registry.addViewController("/sample.html");
44+
}
2645

27-
@Bean
28-
public ViewResolver viewResolver() {
29-
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
46+
@Bean
47+
public ViewResolver viewResolver() {
48+
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
3049

31-
bean.setViewClass(JstlView.class);
32-
bean.setPrefix("/WEB-INF/view/");
33-
bean.setSuffix(".jsp");
50+
bean.setViewClass(JstlView.class);
51+
bean.setPrefix("/WEB-INF/view/");
52+
bean.setSuffix(".jsp");
3453

35-
return bean;
36-
}
54+
return bean;
55+
}
3756
}

‎spring-mvc-xml/src/main/webapp/WEB-INF/view/personForm.jsp‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<h3>Welcome, Enter The Person Details</h3>
2626

27-
<form:form method="POST" action="/spring-mvc-xml/addPerson" modelAttribute="person" enctype="multipart/form-data">
27+
<form:form method="POST" action="/spring-mvc-xml/addPerson" modelAttribute="person">
2828

2929
<form:errors path="*" cssClass="errorbox" element="div" />
3030

@@ -104,10 +104,6 @@
104104
<td><form:label path="notes">Notes</form:label></td>
105105
<td><form:textarea path="notes" rows="3" cols="20"/></td>
106106
</tr>
107-
<tr>
108-
<td><form:label path="file">Select a file to upload</form:label></td>
109-
<td><input type="file" name="file" /></td>
110-
</tr>
111107
<tr>
112108
<td><form:hidden path="id" value="12345"/></td>
113109
</tr>

‎spring-mvc-xml/src/main/webapp/WEB-INF/view/personView.jsp‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,5 @@
6161
<td>${person.notes}</td>
6262
</tr>
6363
</table>
64-
65-
<h2>Submitted File</h2>
66-
<table>
67-
68-
<tr>
69-
<td>OriginalFileName :</td>
70-
<td>${person.file.originalFilename}</td>
71-
</tr>
72-
73-
<tr>
74-
<td>Type :</td>
75-
<td>${person.file.contentType}</td>
76-
</tr>
77-
78-
</table>
7964
</body>
8065
</html>

‎spring-mvc-xml/src/main/webapp/WEB-INF/web.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
3030
<load-on-startup>1</load-on-startup>
3131
<multipart-config>
32-
<location>/tmp</location>
32+
<location>C:/Users/ivan/Desktop/tmp</location>
3333
</multipart-config>
3434
</servlet>
3535
<servlet-mapping>

0 commit comments

Comments
 (0)