我一直在研究如何在Tomcat 8上执行URL重写,并继续运行相同的两个建议.
1)使用Tuckey URLRewriteFilter.2)在Tomcat之上运行Apache以使用mod_rewrite.
对于前者,URLRewriteFilter似乎没有任何关于如何以Java格式配置而不是XML的文档.我的Spring MVC应用程序没有使用web.xml文件 - 所有配置都是通过Java类完成的 - 因此我无法使用XML进行配置.
有没有办法以这种方式配置,或者除了尝试在Tomcat之上运行Apache之外还有什么好的选择吗?
例如,有没有办法在Java中实现这一点而不是XML:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
这是我的WebApplicationInitializer类:
public class Initializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
// Create the 'root' Spring application context
AnnotationConfigWebApplicationContext rootContext =
new AnnotationConfigWebApplicationContext();
rootContext.register(RootConfig.class);
// Manage the lifecycle of the root application context
container.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext =
new AnnotationConfigWebApplicationContext();
dispatcherContext.register(WebAppConfig.class);
// Register and map the dispatcher servlet …Run Code Online (Sandbox Code Playgroud) java tomcat spring-mvc spring-annotations tuckey-urlrewrite-filter
我在functions.php 文件中添加了以下过滤器:
add_filter('widget_text', 'do_shortcode');
Run Code Online (Sandbox Code Playgroud)
这已按预期在我的小部件中启用了短代码。
但是,短代码的内容现在显示在标题上方。我究竟做错了什么?
这就是我通过短代码呼应的内容:
$events_msg = '<div>You have attended <br> <span class="big-num">'. $num_actual_events . '</span> / ' . $num_total_events . ' ' . $event_type . '</br>('. $num_required_events.' required)<br><br></div>';
echo $events_msg;
Run Code Online (Sandbox Code Playgroud)