1
<error-page>
    <error-code>404</error-code>
    <location>/404.html</location>
</error-page>

This is my current configuration for 404 errors.

What I want: When a person types www.host.com/word . I want the string "word" as input for my search url (which is www.host.com/search.do?keyword).

Does anyone know how to do this?

1 Answer 1

3

Map / to your DispatcherServlet (see section 16.2 of the Spring reference documentation) and set up a URI template as shown in section 16.3.2.1. For example, you could set up a request mapping like so:

@RequestMapping(value="/{keyword}", method=RequestMethod.GET)
public ModelAndView doSearch(@PathVariable("keyword") String keyword)
{
  // forward to your search page
}
Sign up to request clarification or add additional context in comments.

6 Comments

<servlet-mapping> <servlet-name>frontend</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet> <servlet-name>frontend</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
Yes, I've amended my answer to link to the relevant section in the Spring documentation. If my answer solved your problem please accept it by clicking the checkmark next to it.
Is it true that everything behind host.com/ is now mapped to the dispatcher? Because my homepage doesnt show up right anymore (css, javascript).
Yes. You could map the servlet to search/ instead so search/{keyword} be the url instead.
Can you give me an example of this please? What to i need to put in the web.xml?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.