Я разрабатываю программное обеспечение на основе Spring и ICEFaces.
У меня есть файл по адресу <project directory>/src/main/webapp/WEB-INF/views/<filename>.xhtml
, доступ к которому осуществляется по следующему URL-адресу: http://<hostname>/<projectname>/<filename>.xhtml
Файл содержит <h:form id="formId">
, который отображается как <form action="/<projectname>/WEB-INF/views/<filename>.xhtml" [.. some other stuff ..]>
.
Это означает, что когда я нажимаю на ввод отправки, содержащийся в форме, браузер пытается открыть URL-адрес http://<hostname>/<projectname>/WEB-INF/views/<filename>.xhtml
и, как я сказал в заголовке, показывает страницу с ошибкой 404.
Я бы хотел, чтобы к файлу .xhtml можно было получить доступ и по «более длинному» URL-адресу. Я почти уверен, что в настоящее время не могу этого добиться из-за ошибки конфигурации.
Это мой web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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_2_5.xsd"
version="2.5">
<web-app>
<display-name>SIGLO</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath: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>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Это файл applicationContext.xml, указанный в предыдущем файле:
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns="http://www.springframework.org/schema/beans"
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/tx
http://www.springframework.org/schema/tx/spring-tx-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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" >
<context:component-scan base-package="com.infoone.siglo" />
<!--
map all requests to /resources/** to the container default servlet
(ie, don't let Spring handle them)
-->
<bean id="defaultServletHttpRequestHandler" class="org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler" />
<bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name="urlMap" >
<map>
<entry key="/resources/**" value-ref="defaultServletHttpRequestHandler" />
</map>
</property>
</bean>
<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />
<mvc:annotation-driven />
<!-- JSF for representation layer. All JSF files under /WEB-INF/views directory -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" >
<property name="cache" value="false" />
<property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean name="icefacesResourceHandler" class="org.springframework.faces.webflow.JsfResourceRequestHandler" />
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order" value="0" />
<property name="mappings">
<value>
/javax.faces.resource/**=icefacesResourceHandler
</value>
</property>
</bean>
</beans>
И, наконец, это мой faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.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-facesconfig_2_0.xsd">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
<locale-config></locale-config>
<resource-bundle>
<base-name>MessageResources</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
Позвольте мне отметить, что эта конфигурация по-прежнему не позволяет мне успешно открыть более короткий URL. Действительно, мне нужно создать правильный контроллер или, лучше, правильный @RequestMapping внутри @Controller:
@RequestMapping(value = "<filename>", method = RequestMethod.GET)
public String creaBlocco()
{
return "<filename>";
}
@RequestMapping(value = "<filename>", method = RequestMethod.POST)
public String creaBlocco([.. parameters ..]) {
[.. stuff ..]
return "<filename>";
}
Да, значение @RequestMapping равно "<filename>"
без расширения .xhtml
. Я уже убедился методом проб и ошибок, что такое сопоставление необходимо для успешного выполнения GET. С другой стороны, я понимаю, что такая конфигурация очень хрупкая. Что мне нужно изменить в моих файлах конфигурации, чтобы сделать <filename>.xhtml
доступным, используя также более длинный URL?
Заранее спасибо за внимание.