Add form tag example

This commit is contained in:
Ivan 2016-03-04 14:49:55 +01:00
parent 09d9cf26b4
commit ecc6625017
5 changed files with 42 additions and 42 deletions

View File

@ -1,6 +1,12 @@
package org.baeldung.spring;
import java.util.Locale;
import java.util.ResourceBundle;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.MessageSourceResourceBundle;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@ -15,7 +21,20 @@ public class ClientWebConfigJava extends WebMvcConfigurerAdapter {
super();
}
// API
@Bean
public MessageSource messageSource() {
final ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
ms.setBasenames("messages");
return ms;
}
@Bean
public ResourceBundle getBeanResourceBundle() {
final Locale locale = Locale.getDefault();
return new MessageSourceResourceBundle(messageSource(), locale);
}
@Override
public void addViewControllers(final ViewControllerRegistry registry) {

View File

@ -24,7 +24,7 @@
<h3>Welcome, Enter The Person Details</h3>
<form:form method="POST" action="/spring-mvc-xml/addPerson" modelAttribute="person" enctype="multipart/form-data">
<form:form method="POST" action="/spring-mvc-xml/addPerson" modelAttribute="person">
<form:errors path="*" cssClass="errorbox" element="div" />
@ -104,10 +104,6 @@
<td><form:label path="notes">Notes</form:label></td>
<td><form:textarea path="notes" rows="3" cols="20"/></td>
</tr>
<tr>
<td><form:label path="file">Select a file to upload</form:label></td>
<td><input type="file" name="file" /></td>
</tr>
<tr>
<td><form:hidden path="id" value="12345"/></td>
</tr>

View File

@ -61,20 +61,5 @@
<td>${person.notes}</td>
</tr>
</table>
<h2>Submitted File</h2>
<table>
<tr>
<td>OriginalFileName :</td>
<td>${person.file.originalFilename}</td>
</tr>
<tr>
<td>Type :</td>
<td>${person.file.contentType}</td>
</tr>
</table>
</body>
</html>

View File

@ -29,7 +29,7 @@
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<multipart-config>
<location>/tmp</location>
<location>C:/Users/ivan/Desktop/tmp</location>
</multipart-config>
</servlet>
<servlet-mapping>