When Session time-out occurred, preRenderView of previous screen is executed - spring

When forward method in the filter executed,
preRenderView of previous screen is executed if a screen transfer in the session time-out state.
ex)Flow of processing
Session time-out: Login -> Start(session time-out) -> Error
(Default:Login -> Start -> End)
When Start transition to Error, preRenderView of Start is executed.
Isn't preRenderView of Error called in usual?
I think the SpringBeanFacesELResolver class is the cause.
Is it right to do such behavior?
Please tell me the cause and a plan to avoid.
It's being checked in the following state (excerpt).
Spring 3.2.5-RELEASE
JDK 1.7.0_76
JSF 2.1
WebLogic 12.1.3
LoginAction.java
#org.springframework.stereotype.Component
#org.springframework.context.annotation.Scope("request")
public class LoginAction implements java.io.Serializable {
public LoginAction() {
}
public String login() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
// The STATUS attribute is set in a session.
session.setAttribute("STATUS", "LOGIN");
return "/Sample/start.xhtml";
}
}
StartAction.java
#org.springframework.stereotype.Component
#org.springframework.context.annotation.Scope("request")
public class StartAction implements java.io.Serializable {
public StartAction() {
}
public void preRenderView(javax.faces.event.ComponentSystemEvent event)
throws javax.faces.event.AbortProcessingException {
// Some process
}
public void preRenderViewOnSystemError(javax.faces.event.ComponentSystemEvent event)
throws AbortProcessingException, IOException {
// Some process
}
public String toEnd() {
return "toEnd";
}
}
TestFilter.java
public class TestFilter implements Filter {
#Override
public void init(FilterConfig config) throws ServletException {
}
#Override
public void destroy() {
}
#Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if(request instanceof HttpServletRequest) {
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpSession session = httpRequest.getSession();
// When the STATUS attribute can't get a session, a forward is executed.
String status = (String)session.getAttribute("STATUS");
if (status == null || "".equals(status)) {
RequestDispatcher rd = request.getRequestDispatcher("/faces/Sample/error.xhtml");
rd.forward(request, response);
}
}
chain.doFilter(request, response);
}
}
start.xhtml
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>Sample Start</title>
</h:head>
<h:body>
<f:event listener="#{startAction.preRenderView}" type="preRenderView"/>
<h:form action="" id="form1" method="post" enctype="multipart/form-data">
<h:commandButton action="#{startAction.toEnd}" id="toEnd" type="submit" value="End"></h:commandButton>
::
</h:form>
</h:body>
</html>
error.xhtml
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>Sample Error</title>
</h:head>
<h:body>
<f:event listener="#{startAction.preRenderViewOnSystemError}" type="preRenderView"/>
<h:form action="" id="form1" method="post">
Error
</h:form>
</h:body>
</html>
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/componentScanSettings.xml
/WEB-INF/datasource-context.xml
</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/Sample/Sample-faces-config.xml, /WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<filter>
<filter-name>multipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>multipartFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>Test</filter-name>
<filter-class>com.xxx.filter.TestFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Test</filter-name>
<url-pattern>/faces/Sample/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- The expiration date of a session is made short. -->
<session-config>
<session-timeout>1</session-timeout>
</session-config>
Sample-faces-config.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<navigation-rule>
<description>Start</description>
<display-name>Start</display-name>
<from-view-id>/Sample/start.xhtml</from-view-id>
<navigation-case>
<from-outcome>toEnd</from-outcome>
<to-view-id>/Sample/end.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
faces-config.xml
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
componentScanSettings.xml
<?xml version="1.0" encoding="UTF-8"?>
<bean
xsi:schemaLocation='http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd'
xmlns:context='http://www.springframework.org/schema/context'
xmlns='http://www.springframework.org/schema/beans'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<context:annotation-config />
<context:component-scan base-package='com.xxx' />
</bean>
datasource-context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<tx:annotation-driven proxy-target-class="true" order="100" />
<bean id="targetDataSource" class="org.springframework.jndi.JndiObjectFactoryBean" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<property name="targetDataSource" ref="targetDataSource" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="filterMultipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>100000</value>
</property>
<property name="maxInMemorySize">
<value>10240</value>
</property>
</bean>
</beans>

Related

Spring: bean with scope=session in jsp

In my Spring MVC project I can't access to the parameters of bean with scope=session.Into Http session there is a bean with name "scopedTarget.user" .I want to print, in jsp page, the User's name.Why is it so difficult to access to this parameters?Where am I wrong?
ControllerHome:
#Controller
public class ControllerHome {
#Autowired
private User user;
#RequestMapping(value="/",method=RequestMethod.GET)
public String welcome(ModelMap model){
model.addAttribute("utente", user);
return "index";
}
#RequestMapping(value="/add",method=RequestMethod.GET)
public String add(#ModelAttribute("utente") User utente,HttpServletRequest request){
HttpSession session=request.getSession();
Enumeration<String> list=session.getAttributeNames();
while(list.hasMoreElements())
System.out.println(list.nextElement());
return "redirect:/";
}
}
index.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form:form method="get" action="add" modelAttribute="utente">
<form:input path="nome"/>
<input type="submit" value="submit">
</form:form>
<c:out value="${sessionScope['scopedTarget.user'].nome}"/>
</body>
</html>
User.java:
public class User implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String nome;
public User(){}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>config</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>config</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
config-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<context:component-scan base-package="controller"/>
<mvc:annotation-driven/>
<bean class="coreservlets.User" id="user" name="user" scope="session">
<aop:scoped-proxy/>
</bean>
</beans>
If you add these anotations #Component and #Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) to the POJO you want to be managed in a session, you can then use it in the JSP using the method you spoke of in your question (and Autowire it in your controllers). Make sure of two things though:
Don't override the toString(), otherwise it's that result that will be assigned to ${sessionScope['scopedTarget.user'].
Your POJO, in this case User, needs to be "caught" by the Spring's component scanner

autowiring an external bean does not work

Im tryin to map the bean called "userVO" to the security controller with annotations, it works when I map it by xml configuration, but I keep getting the following error when I use annotations
WARNING: /login.xhtml #22,37 value="#{securityController.userVO.vc_name}": Target unreacheable, 'userVO' returned null
I must say UserVO is in a different project that I also own, and its dependency is handled with maven
The following is my spring-beans config file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<import resource="mapper-beans.xml" />
<bean name="userVO" id="userVO" class="rst.core.security.UserVO"
scope="session" />
<context:annotation-config />
<context:component-scan base-package="rst.core.security" />
<context:component-scan base-package="rst.controller" />
</beans>
The following is the controller with the mapping to userVO that its not working:
#ManagedBean
#RequestScoped
#Controller
public class SecurityController {
public static Logger log;
private WebFacade webFacade;
#Autowired
private UserVO userVO;
public SecurityController() {
log = LoggerFactory.getLogger(this.getClass());
log.debug("Creating SecurityController.");
}
public String login() {
UserVO user= webFacade.validateUser(getUserVO()); // method to search the db
if (user!= null) {
return "accessGranted";
} else {
return "accessDenied";
}
}
//getters and setters....
}
Also this is the login screen that triggers the error:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form id="form">
<p:panel id="panel" header="New Person">
<h:panelGrid columns="3">
<h:outputLabel for="name" value="Name: *" />
<p:inputText id="name" value="#{securityController.userVO.vc_name}"
label="name" required="true"/>
<h:outputLabel for="password" value="Password: *" />
<p:inputText id="password" value="#{securityController.userVO.vc_password}"
required="true" label="Password" type="password"/>
</h:panelGrid>
<p:commandButton id="btn" value="Login" update="panel"
action="#{securityController.login}"/>
</p:panel>
</h:form>
</h:body>
</html>
And the following is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee /web-app_3_0.xsd">
<display-name>rst-web</display-name>
<!---+++++++++++++++++++++++++++++++++++++++++++++++++Spring++++++++++++++++++++++++++++++++++++++++++-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-beans.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- ++++++++++++++++++++++++ JSF +++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/login.xhtml</welcome-file>
</welcome-file-list>
</web-app>
How is securityController resolved? It is marked with #ManagedBean which makes it visible to JSF, on the other hand JSF won't recognize spring's #Autowired when instantiating SecurityManager.
If you want to stick to spring, get rid of #ManagedBean, change #RequestScoped to #Scope("request") and make sure you have set up ELResolver correctly in faces-config:
<faces-config>
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
...
</application>
</faces-config>

Getting correct html form action attribute with JSF + Spring 3

I am trying to mix Spring MVC with Java Server Faces. I have a Spring 3.2 #Controller class, which returns a ModelAndView that is resolved to a JSF view. That view contains a <h:form> tag. The problem that I am having is that, on the rendered HTML, the form action attribute combines the original request URL with the name to resolve the view, creating a strange meaningless URL to which the form is POSTed. What I want is just the view name, without the original request URL.
Here is my controller class (org.my.test.MainController):
#Controller
#RequestMapping("/items")
public class MainController
{
#RequestMapping(value="/{itemId}", method=RequestMethod.GET)
public ModelAndView retrieveItem( #PathVariable long itemId ) {
/* Retrieve item */
ModelAndView mav = new ModelAndView();
mav.addObject ("itemName", "A retrieved item");
mav.addObject ("itemId", itemId);
mav.setViewName ("/items");
return mav;
}
}
Here is my JSF template (/items.xhtml)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Edit item</title>
</h:head>
<h:body>
<h:form>
<h3>Edit item</h3>
<p>
Item name: <h:inputText name="itemName" value="#{itemName}" />
</p>
<p>
Item id: <h:inputText name="itemId" value="#{itemId}" />
</p>
<p>
<h:commandButton value="Submit" />
</p>
</h:form>
</h:body>
</html>
When I request the page http://localhost:8081/items/12345, what is served is this:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Edit item</title></head><body><form id="j_id_6" name="j_id_6" method="post" action="/items/12345/items.xhtml" enctype="application/x-www-form-urlencoded">
<h3>Edit item</h3>
<p>
Item name: <input id="j_id_6:j_id_8" name="j_id_6:j_id_8" type="text" value="A retrieved item" />
</p>
<p>
Item id: <input id="j_id_6:j_id_a" name="j_id_6:j_id_a" type="text" value="12345" />
</p>
<p><input id="j_id_6:j_id_c" name="j_id_6:j_id_c" type="submit" value="Submit" />
</p><input type="hidden" name="j_id_6_SUBMIT" value="1" /><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="oyc7wGGKZrPGinPPmrv9PmTDy0GBlI3c+pjWpdK0KuY69faJ" /></form></body>
</html>
My problem is the bit that says action="/items/12345/items.xhtml" What I want is action="/items" or action="/items.xhtml"
My question has two parts: why is my setup combining the request URL with the view ID like this, and how do I make it stop?
Here is web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Minimal JSF + Spring test</display-name>
<!-- - Location of the XML file that defines the root application context.
- Applied by ContextLoaderListener. -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/spring/application-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<!-- - Servlet that dispatches request to registered handlers (Controller
implementations). -->
<servlet>
<servlet-name>ui</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ui-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ui</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Just here so the JSF implementation can initialize, *not* used at runtime -->
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Just here so the JSF implementation can initialize -->
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>
Here is Spring config ui-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:faces="http://www.springframework.org/schema/faces"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="org.my.test" />
<mvc:annotation-driven />
<bean id="faceletsViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
<property name="prefix" value="" />
<property name="suffix" value=".xhtml" />
</bean>
</beans>
Here is main Spring config application-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:faces="http://www.springframework.org/schema/faces"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="org.my.test" />
</beans>
And here is faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
This is all running in embedded Jetty 9.0.4. I have tried two different JSF implementations, Apache My-Faces 2.1.11 and Mojarra 2.2.1, both with the same effect. Spring version is 3.2.3.
Changing the url-mapping in web.xml from "/" to "/*" corrected the problem.
Everything is in fact behaving according to the Servlet spec (Java Servlet Specification Version 3.0 Rev a, Section 12.2, page 116):
A string beginning with a / character and ending with a /* suffix is used for path mapping.
...
A string containing only the / character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
(Thank you to this post on Coderanch: http://www.coderanch.com/t/366340/Servlets/java/servlet-mapping-url-pattern)
(Java Servlet 3.0 spec available at http://download.oracle.com/otndocs/jcp/servlet-3.0-mrel-eval-oth-JSpec/)

Integration of JSF 2, Spring 3.1 and Hibernate 4.1 in Eclipse

According to my previous question integration of jsf2.0 and spring 3.1 and hibernate 4.1
I think my code has problem. I am really confused. I did as other advised but still getting error 404:Description The requested resource (/jsfspringhiber/default.xhtml) is not available. I don't use maven.
Customer.java
package main;
public class Customer{
public long customerId;
public String name;
public String address;
public String createdDate;
public long getCustomerId() {
return customerId;
}
public void setCustomerId(long customerId) {
this.customerId = customerId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCreatedDate() {
return createdDate;
}
public void setCreatedDate(String createdDate) {
this.createdDate = createdDate;
}
}
CustomerBean.java
package main;
import java.io.Serializable;
import java.util.List;
import main.CustomerBo;
import main.Customer;
public class CustomerBean implements Serializable{
CustomerBo customerBo;
public String name;
public String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public void setCustomerBo(CustomerBo customerBo) {
this.customerBo = customerBo;
}
public CustomerBo getCustomerBo() {
return customerBo;
}
//get all customer data from database
public List<Customer> getCustomerList(){
return customerBo.findAllCustomer();
}
//add a new customer data into database
public String addCustomer(){
Customer cust = new Customer();
cust.setName(getName());
cust.setAddress(getAddress());
customerBo.addCustomer(cust);
clearForm();
return "";
}
//clear form values
private void clearForm(){
setName("");
setAddress("");
}
}
CustomerBo.java
import java.util.List;
import main.Customer;
public interface CustomerBo{
void addCustomer(Customer customer);
List<Customer> findAllCustomer();
}
CustomerBoImpl.java
public class CustomerBoImpl implements CustomerBo{
CustomerDao customerDao;
public void setCustomerDao(CustomerDao customerDao) {
this.customerDao = customerDao;
}
public void addCustomer(Customer customer){
customerDao.addCustomer(customer);
}
public List<Customer> findAllCustomer(){
return customerDao.findAllCustomer();
}
}
CustomerDao.java
public interface CustomerDao{
void addCustomer(Customer customer);
List<Customer> findAllCustomer();
}
CustomerDaoImpl.java
public class CustomerDaoImpl implements CustomerDao{
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public void addCustomer(Customer customer){
getSessionFactory().getCurrentSession().save
(customer);
}
public List<Customer> findAllCustomer(){
List list = getSessionFactory().getCurrentSession
().createQuery("from Customer").list();
return list;
}
}
Customer.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 27, 2012 1:01:10 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="main.Customer" table="CUSTOMER">
<id name="customerId" type="long">
<column name="CUSTOMER_ID" />
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" />
</property>
<property name="createdDate" type="java.lang.String">
<column name="CREATED_DATE" />
</property>
</class>
</hibernate-mapping>
CustomerBean.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1xsd">
<bean id="customerBo"
class="main.CustomerBoImpl" >
<property name="customerDao" ref="customerDao" />
</bean>
<bean id="customerDao"
class="main.CustomerDaoImpl" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
DataSource.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#Mohsen-PC:1521:mydb" />
<property name="username" value="system" />
<property name="password" value="123" />
</bean>
</beans>
HibernateSessionFactory.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<!-- Hibernate session factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>main/Customer.hbm.xml</value>
</list>
</property>
</bean>
</beans>
applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<!-- Database Configuration -->
<import resource="main/DataSource.xml"/>
<import resource="main/HibernateSessionFactory.xml"/>
<!-- Beans Declaration -->
<import resource="main/CustomerBean.xml"/>
</beans>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
<managed-bean>
<managed-bean-name>customer</managed-bean-name>
<managed-bean-class>main.CustomerBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>customerBo</property-name>
<value>#{customerBo}</value>
</managed-property>
</managed-bean>
</faces-config>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>jsfspringhiber</display-name>
<!-- Add Support for Spring -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>default.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
default.xhtml
<<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
>
<h:head>
<h:outputStylesheet library="css" name="table-style.css" />
</h:head>
<h:body>
<h1>JSF 2.0 + Spring + Hibernate Example</h1>
<h:dataTable value="#{customer.getCustomerList()}" var="c"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
>
<h:column>
<f:facet name="header">
Customer ID
</f:facet>
#{c.customerId}
</h:column>
<h:column>
<f:facet name="header">
Name
</f:facet>
#{c.name}
</h:column>
<h:column>
<f:facet name="header">
Address
</f:facet>
#{c.address}
</h:column>
<h:column>
<f:facet name="header">
Created Date
</f:facet>
#{c.createdDate}
</h:column>
</h:dataTable>
<h2>Add New Customer</h2>
<h:form>
<h:panelGrid columns="3">
Name :
<h:inputText id="name" value="#{customer.name}"
size="20" required="true"
label="Name" >
</h:inputText>
<h:message for="name" style="color:red" />
Address :
<h:inputTextarea id="address" value="#{customer.address}"
cols="30" rows="10" required="true"
label="Address" >
</h:inputTextarea>
<h:message for="address" style="color:red" />
</h:panelGrid>
<h:commandButton value="Submit" action="#{customer.addCustomer()}" />
</h:form>
</h:body>
</html>
the structure of my project:
Lets do one thing, Here is the code for a basic skeleton for integrating Spring and JSF. If you are able to see the login page with this code then we will build the solution out of this.
Create a new Dynamic Web Project with the following files:
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
version="3.0">
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
</web-app>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.examples" />
</beans>
Test pages: index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Welcome</title>
</h:head>
<h:body>
<h:form>
<h3>Please enter your name and password.</h3>
<table>
<tr>
<td>Name:</td>
<td><h:inputText value="#{userBean.name}"/></td>
</tr>
<tr>
<td>Password:</td>
<td><h:inputSecret value="#{userBean.password}"/></td>
</tr>
</table>
<p><h:commandButton value="Login" action="welcome"/></p>
</h:form>
</h:body>
</html>
welcome.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Welcome</title>
</h:head>
<h:body>
<h3>Spring integration with JavaServer Faces Successful, #{userBean.name}!</h3>
</h:body>
</html>
And finally the backing bean: UserBean.java
package com.examples;
import java.io.Serializable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
#Component
#Scope("request")
public class UserBean implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private String password;
public String getName() { return name; }
public void setName(String newValue) { name = newValue; }
public String getPassword() { return password; }
public void setPassword(String newValue) { password = newValue; }
}
That's it, nothing more. Just copy and paste this code into a sample project and lets see what we can do later. One more thing I noticed is that your lib folder under WEB-INF seems empty. You will need the following jars to run this project:
Download Latest GA release of Spring Framework from here and include the jars in the dist folder of the zip file.
Download JSF jars from here, you can grab the latest 2.1.10.
Include commons-logging jar from here
i use maven. the correct answer is here.
the structure is:

No mapping found for HTTP request with URI in DispatcherServlet with name 'dispatcher'

I'm new to Spring framework. I just started implementing multiaction controller in netbeans. But. I'm getting the above error. I'm pasting my code below. Plz take a look into it and resolve me the issue.
dispatcher-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<bean name="/*.htm" class="controller.MyController"/>
</beans>
index.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello</title>
</head>
<body>
<h4>Multi Action Controller Example</h4>
Add
Update
Remove
</body>
</html>
MyController.java:
package controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
public class MyController extends MultiActionController {
public ModelAndView add(HttpServletRequest req, HttpServletResponse resp) throws Exception {
System.out.println("Add ma");
return new ModelAndView("result","message","Add Method Called");
}
public ModelAndView update(HttpServletRequest req, HttpServletResponse resp) throws Exception {
System.out.println("Update ma");
return new ModelAndView("result","message","Update Method Called");
}
public ModelAndView remove(HttpServletRequest req, HttpServletResponse resp) throws Exception {
System.out.println("Remove ma");
return new ModelAndView("result","message","Remove Method Called");
}
}
result.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Nee Varaatha</title>
</head>
<body>
<h1>Please Show it </h1>
${message}
</body>
</html>
Try checking your apachelog in the output Window of netbeans and see what's the default mapping of your controller in it, and append that mapping in the index.jsp.
For example in the log you'll find
Mapped URL path [/employee] onto handler '/*.html'
Simply append employee/add.htm in the JSP
Have you considered using #Controller annotated classes? Since spring 2.5 annotations are usually preferred.
Here's an example web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
<display-name>Example</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/example-servlet.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
example-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!--Tell the servlet where to look for annotated methods-->
<context:component-scan base-package="controller" />
<!--if no controller logic is required, mvc:view-controller can be used to simply show a view for a request -->
<mvc:view-controller path="/" view-name="index"/>
<!--Enables many annotations and searches for #Controller annotated methods etc.. -->
<context:annotation-config />
<!--JSR-303 (Bean validation) support will be detected on classpath and enabled automatically-->
<mvc:annotation-driven />
<!--This tag allows for mapping the DispatcherServlet to "/" (all extensions etc)-->
<mvc:default-servlet-handler/>
<mvc:resources location="/resources/**, classpath:resources" mapping="/resources/**"/>
<!--Configures the application to search for views in folder /WEB-INF/jsp/ with the suffix ".jsp"
in controllers prefix and suffix are therefore no longer needed-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
And an example simple controller:
#Controller
public class ExampleController {
#RequestMapping("/test")
public String test(Model model) {
model.addAttribute("message","Test message");
return "result";
}
}
Also see the spring reference documentation here

Resources