Ans)
Spring MVC frame work is another popular MVC framework for Web Apps like Struts.
Below is the sample Spring MVC configuration for the Log In Functionality.
Step 1 :
public class StartController extends SimpleFormController {
@Override
protected ModelAndView onSubmit(HttpServletRequest httpServletRequest, HttpServletResponse
httpServletResponse, Object o, BindException e) throws Exception {
StartForm form = (StartForm) o;
if (form.getCommand().equals("startForm")) {
return new ModelAndView(new RedirectView("newOrder/newOrder.htm"));
}
}
@Override
protected Object formBackingObject(HttpServletRequest httpServletRequest) throws Exception {
AddDocumentForm form = new AddDocumentForm();
return form;
}
@Override
protected Map referenceData(HttpServletRequest request, Object o, Errors errors) throws Exception {
Map<String, Object> map = super.referenceData(request, o, errors);
return map;
}
}
View :
<bean name="/start.htm" class="com.salesorder.StartController">
<property name="sessionForm" value="true"/>
<property name="commandName" value="startForm"/>
<property name="commandClass" value="com.salesorder.StartForm"/>
<property name="formView" value="salesorder/start"/>
<property name="successView" value="start.htm"/>
</bean>
Resolver :
Views in Spring are addressed by a view name and are resolved by a view resolver,
Spring Offers Several View Resolvers such as "AbstractCachingViewResolver",
"XmlViewResolver","ResourceBundleViewResolver","InternalResourceViewResolver",
"VelocityViewResolver".
Each of the above solves different technical solution and offers different
functionality.
"InternalResourceViewResolver" is most commonly used one , could be used as follows.
<bean id="viewResolver" class="
org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>