User Manual

import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import java.util.Date;
public class EmployeeController extends SimpleFormController {
protected final Log logger = LogFactory.getLog(getClass());
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String now = (new Date()).toString();
logger.info("Returning view with " + now);
return new ModelAndView("WEB-INF/jsp/insert.jsp", "now", now);
}
}
The code of the EmpInfo application developed so far is located in <My SASH
Home>\spring\getting-started\EmpInfo-InParts\Part-3
At this point, you can either deploy and verify the EmpInfo application you have developed so far
on the NonStop system, or you can continue with the steps explained in “Decoupling View from
the Controller” (page 61).
For deployment, see the steps described in “Deploying EmpInfo on NonStop” (page 87).
You can verify the EmpInfo application by accessing the following URL:
http://<IP Address of the iTP WebServer>:<port#>/<servlet directory>/EmpInfo.
Decoupling View from the Controller
So far, the controller is specifying full path of the view, thereby creating unnecessary dependency
between the controller and the view. Ideally, the view must be mapped using a logical name, so
that the view can be switched without changing the controller.
To decouple the view from the controller:
1. Modify the EmpInfo-servlet.xml file in the EmpInfo/WebContent/WEB-INF directory
to add the following bean to declare a new ViewResolver entry.
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix"
value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
2. Modify the EmployeeController class EmpInfo/com/hp/empinfo/web/
EmployeeController.java to decouple the controller from view using ViewResolver
, as shown:
Before modification:
return new ModelAndView("WEB-INF/jsp/insert.jsp", "now", now);
After modification:
return new ModelAndView("insert", "now", now);
The code of the EmpInfo application developed so far is located in <My SASH
Home>\spring\getting-started\EmpInfo-InParts\Part-4
At this point, you can either deploy and verify the EmpInfo application you have developed so far
on the NonStop system, or you can continue with the steps described in “Developing Business
Logic and Providing the Web Interface” (page 62).
For deployment, see the steps described in “Deploying EmpInfo on NonStop” (page 87).
You can verify the EmpInfo application by accessing the following URL:
Getting Started with Spring 61