PDA

View Full Version : How to shorten the URL's


leetgeezer
Mar 26th, 2007, 01:02 PM
Hello,
Let's say I have a server: "test.com", a web-app named "testapp" running on Tomcat 5.5

I can't really figure out how to configure my <servlet-mapping> and/or the controller mapping(s) so that the address
http://server.com/testapp/login

gets mapped to the LoginController.

The problem is that all the examples use something like

<url-pattern>/app/*</url-pattern>

which introduces a redundant (for me) URL fragment. I mean, the URL
becomes then

http://server.com/testapp/app/login

In that case there is no problem to configure the controller.

I tried several configurations of <url-pattern>, namely *, /*, */** etc, but none of them seems to work for me. The request is not redirected to the controller.

How to make it work without the '/app' part?

Dosihris
Mar 26th, 2007, 01:57 PM
Try this. Its a part from my SpringDispatcher-servlet.xml

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">

<property name="urlMap">
<map>
<entry key="login">
<ref bean="LoginBean"/>
</entry>
</map>
</property>
</bean>

leetgeezer
Mar 27th, 2007, 05:56 AM
Thx. But what is inside your sevlet-mapping?

Dosihris
Mar 27th, 2007, 06:15 AM
Do you mean the code inside the LoginBean?


Its a normal Controller.

Something like this
public class LoginController implements Controller
{
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
{
// Handle here all what you want to do
// Parameters, ect...

ModelAndView mav = new ModelAndView("login");

return mav;
}
}

leetgeezer
Mar 28th, 2007, 04:39 AM
No, I mean, can you show me your web.xml file?

cmelgar
Mar 28th, 2007, 05:57 AM
Just use "/" - this makes the servlet the default servlet that will handle any request not matched by another mapping.

Chris

leetgeezer
Apr 2nd, 2007, 03:41 AM
Thank you. I'll try it when I get home