Add form tag example
This commit is contained in:
parent
09d9cf26b4
commit
ecc6625017
@ -8,10 +8,10 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
||||
@Configuration
|
||||
public class ClientWebConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
public ClientWebConfig() {
|
||||
super();
|
||||
}
|
||||
public ClientWebConfig() {
|
||||
super();
|
||||
}
|
||||
|
||||
// API
|
||||
// API
|
||||
|
||||
}
|
@ -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;
|
||||
@ -11,27 +17,40 @@ import org.springframework.web.servlet.view.JstlView;
|
||||
//@Configuration
|
||||
public class ClientWebConfigJava extends WebMvcConfigurerAdapter {
|
||||
|
||||
public ClientWebConfigJava() {
|
||||
super();
|
||||
}
|
||||
public ClientWebConfigJava() {
|
||||
super();
|
||||
}
|
||||
|
||||
// API
|
||||
@Bean
|
||||
public MessageSource messageSource() {
|
||||
|
||||
@Override
|
||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
||||
super.addViewControllers(registry);
|
||||
final ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
|
||||
ms.setBasenames("messages");
|
||||
return ms;
|
||||
}
|
||||
|
||||
registry.addViewController("/sample.html");
|
||||
}
|
||||
@Bean
|
||||
public ResourceBundle getBeanResourceBundle() {
|
||||
|
||||
@Bean
|
||||
public ViewResolver viewResolver() {
|
||||
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
||||
final Locale locale = Locale.getDefault();
|
||||
return new MessageSourceResourceBundle(messageSource(), locale);
|
||||
}
|
||||
|
||||
bean.setViewClass(JstlView.class);
|
||||
bean.setPrefix("/WEB-INF/view/");
|
||||
bean.setSuffix(".jsp");
|
||||
@Override
|
||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
||||
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;
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
@ -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>
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user