1

I'm making an webapp using react and spring mvc. I've got 2 questions while making it.

  1. How do you request mapping? I want to map all the uris but resources and apis into index.jsp, react SPA entry.

    • resouce uris start with /res
    • api uris start with /api
  2. How do you response url that react recognize. I mean If you put /examples/1 on your browser, then the web server retutns index.jsp with uri /examples/1 so that react redirects itself to /examples/1.

Thanks.

1 Answer 1

2

I've made a controller like this,

@RequestMapping("/api/**")
public ApiResult api(HttpServletRequest request, HttpServletResponse response){
    return apiProxy.proxy(request, reponse);
}

@RequestMapping(value="/**", method=HTTPMethod.GET)
public String index(){
    return "index"
}

and setup spring config like this.

<mvc:resource mapping="/res/**" location="/res/" order="-1"/>

order -1 is very important. It makes spring to check first the request url matches with resource mapping.

Sign up to request clarification or add additional context in comments.

2 Comments

can you advise how did your web.xml looked like?
@kvatashydze hmm I don't remember it actually. But I'm sure that I had a servlet of org.springframework.web.servlet.DispatcherServlet and mapped it to all the urls.

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.