ฉันกำลังพัฒนาซอฟต์แวร์โดยใช้ 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 ..]>
หมายความว่าเมื่อฉันคลิกที่ input send ที่มีอยู่ในแบบฟอร์ม เบราว์เซอร์จะพยายามเปิด 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 ยาวขึ้น ด้วย
ขอขอบคุณล่วงหน้าสำหรับความสนใจของคุณ