• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to change /faces/* url pattern

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
I have jsp page named first.jsp. I want its url to be /first only instead of /faces/first.jsp without the .jsp extenssion. Is there any way of doing it in JSF.
 
Ranch Hand
Posts: 160
IntelliJ IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Fawad Ali wrote:Hello All,
I have jsp page named first.jsp. I want its url to be /first only instead of /faces/first.jsp without the .jsp extenssion. Is there any way of doing it in JSF.


To remove the 'faces' part of the url, I think you could change

to

in your web.xml file. I'm not sure if this is a good idea though. As for hiding the extension, I'm not sure how you would accomplish that.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What makes JSF URLS be JSF URLs is that the are directed to the FacesServlet. They are directed there because of the URL mapping statement. URLs that match the mapping pattern get routed to the FacesServlet because that's how J2EE URL routing works. It's that simple.

So if you really want to mess with people, you could just as easily have made a mapping pattern like "*.aspx" or "/uglyfaces/*".
 
Fawad Ali
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys for your replies. Well I found a soultion for this. In web.xml I specified this URL pattern.

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<session-config>

which removes the faces in start and converts the .jsp extenssion to .faces. Then I made a filter so that each request is first passed from that filter which is

<filter>
<filter-name>URLFilter</filter-name>
<filter-class>com.soft.autohaul.Filter.URLFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>URLFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

which means any request will first pass through the URLFilter class which as follows


import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class URLFilter implements Filter {

public void destroy() {
// TODO Auto-generated method stub

}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletRequest httpServletRequest = ((HttpServletRequest)request);
String dispatchURL =((HttpServletRequest)request).getServletPath()+".faces";
try{

httpServletRequest.getRequestDispatcher(dispatchURL).forward(request, response);
}catch(Exception e){
}

}


public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}

}

Si if I want to visit "first.jsp". I will write only "first" in browser without the extenssion. The request will go to filter which will add the ".faces" extenssion to it. After that the request will be dispatched to faces Servlet.
Hope it helps others.

 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like a very clever solution. Well done!
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just Curious, what is the reason you don't want to type the extension?

And i think there should be some easy way to do it right?

Let me do some digging
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Naveen, you're awakened a zombie. This thread was last updated over a year ago.

But a lot of people don't like URLs with filename-type extensions on them. That's one of the things that PrettyFaces is designed for.
 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops..............

i might have searched for something in the forum and found this thread interesting and ...................
 
reply
    Bookmark Topic Watch Topic
  • New Topic