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

@ -8,10 +8,10 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@Configuration @Configuration
public class ClientWebConfig extends WebMvcConfigurerAdapter { public class ClientWebConfig extends WebMvcConfigurerAdapter {
public ClientWebConfig() { public ClientWebConfig() {
super(); super();
} }
// API // API
} }

View File

@ -1,6 +1,12 @@
package org.baeldung.spring; 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.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.ViewResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@ -11,27 +17,40 @@ import org.springframework.web.servlet.view.JstlView;
//@Configuration //@Configuration
public class ClientWebConfigJava extends WebMvcConfigurerAdapter { public class ClientWebConfigJava extends WebMvcConfigurerAdapter {
public ClientWebConfigJava() { public ClientWebConfigJava() {
super(); super();
} }
// API @Bean
public MessageSource messageSource() {
@Override final ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
public void addViewControllers(final ViewControllerRegistry registry) { ms.setBasenames("messages");
super.addViewControllers(registry); return ms;
}
registry.addViewController("/sample.html"); @Bean
} public ResourceBundle getBeanResourceBundle() {
@Bean final Locale locale = Locale.getDefault();
public ViewResolver viewResolver() { return new MessageSourceResourceBundle(messageSource(), locale);
final InternalResourceViewResolver bean = new InternalResourceViewResolver(); }
bean.setViewClass(JstlView.class); @Override
bean.setPrefix("/WEB-INF/view/"); public void addViewControllers(final ViewControllerRegistry registry) {
bean.setSuffix(".jsp"); super.addViewControllers(registry);
return bean; registry.addViewController("/sample.html");
} }
@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setViewClass(JstlView.class);
bean.setPrefix("/WEB-INF/view/");
bean.setSuffix(".jsp");
return bean;
}
} }

View File

@ -24,7 +24,7 @@
<h3>Welcome, Enter The Person Details</h3> <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" /> <form:errors path="*" cssClass="errorbox" element="div" />
@ -104,10 +104,6 @@
<td><form:label path="notes">Notes</form:label></td> <td><form:label path="notes">Notes</form:label></td>
<td><form:textarea path="notes" rows="3" cols="20"/></td> <td><form:textarea path="notes" rows="3" cols="20"/></td>
</tr> </tr>
<tr>
<td><form:label path="file">Select a file to upload</form:label></td>
<td><input type="file" name="file" /></td>
</tr>
<tr> <tr>
<td><form:hidden path="id" value="12345"/></td> <td><form:hidden path="id" value="12345"/></td>
</tr> </tr>

View File

@ -61,20 +61,5 @@
<td>${person.notes}</td> <td>${person.notes}</td>
</tr> </tr>
</table> </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> </body>
</html> </html>

View File

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