我有一个测试项目,我想用Pretty Rewrite(http://www.ocpsoft.org/rewrite/)重写我的网址
我试过的是添加
rewrite-servlet-3.0.0.Alpha4.jar
到我的netbeans项目,我在 WEB-INF 文件夹中创建了一个名为 pretty-config.xml 的xml文件。
我的 pretty-config.xml 是
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
<url-mapping id="home">
<pattern value="/home"/>
<view-id value="faces/index.xhtml"/>
</url-mapping>
</pretty-config>
我的 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">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
并制作&#34; ApplicationConfigurationProvider &#34;在默认包
中 import javax.servlet.ServletContext;
import org.ocpsoft.logging.Logger.Level;
import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.config.Direction;
import org.ocpsoft.rewrite.config.Log;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
import org.ocpsoft.rewrite.servlet.config.Path;
import org.ocpsoft.rewrite.servlet.config.Redirect;
@RewriteConfiguration
public class ApplicationConfigurationProvider extends
HttpConfigurationProvider {
@Override
public Configuration getConfiguration(ServletContext context) {
return (ConfigurationBuilder.begin()
.addRule().perform(Log.message(Level.INFO, "Rewrite is active :D."))
.addRule()
.when(Direction.isInbound().and(Path.matches("/")))
.perform(Redirect.temporary(context.getContextPath() + "/home")));
}
@Override
public int priority() {
return 0;
}
}
但是当我尝试访问我的网页 http://localhost:8080/JSFTEst/home 时 它给出了404错误,我的服务器是tomcat apache-tomcat-7.0.57
我在这里缺少什么,请帮助我。谢谢:)