我目前正在尝试做一个CMS项目,在那里我将做一个所谓的“博客网站”,类似于wordpress。我面临的问题是,我想通过url直接访问博客网站。
类似于local/CMS/site_name的内容
通常它会是一个404错误,因为没有任何东西会被映射到那里,所以我在web.xml中捕获了它
<error-page>
<error-code>404</error-code>
<location>/checkBlogUrl.action</location>
</error-page>因此,我可以在那里处理URL请求,查询网站,如果它存在,将页面转发到那里,如果不是error.jsp。
我目前尝试让它工作的代码是
HttpServletRequest request = ServletActionContext.getRequest();
String a = request.getServerName() +" : " + request.getRequestURI()
+ " : "+ request.getServletPath() +" : "+ request.getLocalName();
System.out.println(a);不幸的是,它返回了这个
操作: /checkBlogUrl.action : mycms : mycms
如何获取site_name?或者,有没有更好的方法来“转发”数据库查询的url?
发布于 2016-04-21 17:53:27
我没有在web.xml中使用错误页面,而是将其更改为命名参数。
<action name="/*" class="checkBlogUrl">
<param name="blogSiteUrl">{1}</param>
<result type="redirectAction">
<param name="actionName">checkBlogUrl</param>
<param name="blogSiteUrl">{1}</param>
</result>
</action>正如Andrea Ligios所指出的,web.xml错误页面将丢弃原始的请求URI,因此这个问题是不可行的
编辑:
将${requestScope'javax.servlet.error.request_uri'}放在JSP页面中会得到URI,然后您可能会以某种方式将其传递给操作
https://stackoverflow.com/questions/36759327
复制相似问题