Wordpress-like Urlrewriting in JSP, Tomcat with Urlrewritefilter

I am developing simple cms for an online health magazine using JSP, Tomcat and urlrewritefilter to rewrite URLs. I am transferring content from Wordpress and must maintain permalinks on the site. Permalinks looks below, only letters and numbers.

http://www.example.com/post-or-category-name-with-letters-or-1234/ 

I want to rewrite my url in my jsp application so that I have URLs like the ones described above. The Rewrite rule should work as follows.

 http://www.example.com/post/?pid=1234&name=post-name http://www.example.com/category/?cid=1234&slug=category-slug 

in

 http://www.example.com/post-name/ http://www.example.com/category-slug/ 

And, of course, vice versa.

How can I use permalink structure in Wordpress using urlrewritefilter? Do I need to write a servlet to get the identifier of a name or bullet from the database?

Does anyone have an idea how to do this or do it earlier?

+4
source share
2 answers

I already created a JavaServer Faces CMS with a custom URL for posts and categories. I used mainly javax.servlet.Filter and javax.faces.application.ViewHandler . Since you are in direct JSP, you will not need javax.faces.application.ViewHandler .

How I declared my filter:

 <filter> <filter-name>URLFilter</filter-name> <filter-class>com.spectotechnologies.jsf.filters.URLFilter</filter-class> <async-supported>true</async-supported> </filter> <filter-mapping> <filter-name>URLFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping> 

Implementation of the main filter:

 /** * * @author Alexandre Lavoie */ public class URLFilter implements Filter { @Override public void doFilter(ServletRequest p_oRequest, ServletResponse p_oResponse, FilterChain p_oChain) throws IOException, ServletException { // Determining new url, get parameters, etc p_oRequest.getRequestDispatcher("newurl").forward(p_oRequest,p_oResponse); } @Override public void init(FilterConfig p_oConfiguration) throws ServletException { } @Override public void destroy() { } } 
+1
source

All Articles