Spring + Tiles. How to return 301 redirect (instead of 302) in Controller

Escander

I am using the code like:

@RequestMapping(value="/oldPath")
public String doProductOld(
    @PathVariable(value = "oldProductId") Long oldProductId,
   Model model
) throws Exception {
    Product product = productDao.findByOldId(oldProductId);

    return "redirect:" + product.getUrlNewPath();
 }

All works fine but this redirect returns 302 response code instead of 301 which is needed for SEO. How to easily (without ModelAndView or Http response) update it to return 301 code?

PS. I found solutions when ModelAndView object return from controller but need solution for Tiles when tiles alias (String) is returned.

msangel

General idea is:

@RequestMapping(value="/oldPath")
public ModelAndView doProductOld(
    @PathVariable(value = "oldProductId") Long oldProductId,
   Model model
) throws Exception {
    Product product = productDao.findByOldId(oldProductId);
    RedirectView red = new RedirectView(product.getUrlNewPath(),true);
    red.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    return new ModelAndView(red);
 }

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to return Controller instead of View in RequestMapping in Spring?

분류에서Dev

301 Redirect to a 302 Redirect (SEO implications)

분류에서Dev

how to return two lists from controller class in spring mvc

분류에서Dev

how to do 301 redirect of the same URL with a difference in hypen

분류에서Dev

301 .htacess redirect issue

분류에서Dev

Response.Redirect (url)는 firefox 개발자 콘솔에 301과 302를 보여줍니다.

분류에서Dev

How to redirect user from controller to another domain

분류에서Dev

301 redirect for all get request

분류에서Dev

301 Redirect a folder to a single page

분류에서Dev

htaccess 301 redirect -- remove a string

분류에서Dev

htaccess 301 redirect — remove a path

분류에서Dev

Firefox: How to get my home page in new tabs, instead of the recent sites 'tiles' thing :(

분류에서Dev

How can I return two values in a controller

분류에서Dev

how to put confirm alert in controller and redirect to perticular link if cancel it in yii

분류에서Dev

Redirect 301 on changed root name not working

분류에서Dev

301 redirect complete url to different extension, BUT with exceptions

분류에서Dev

Redirect 301 in htaccess changes the url encoding

분류에서Dev

HTACCESS 301 redirect issue with strange url variables

분류에서Dev

htaccess redirect 301 https www to non www

분류에서Dev

How to send json instead of params in spring test

분류에서Dev

How to add a constructor in Controller via Spring

분류에서Dev

Spring Security 302 리디렉션

분류에서Dev

How to return 404 when resource is not found, instead of HTML

분류에서Dev

How to get this Python method to return a string instead of writing it to stdout?

분류에서Dev

CodeIgniter, how to return multiple queries from model to controller?

분류에서Dev

Vue.js에서 JavaScript로 GET 301/302 응답 처리

분류에서Dev

SEO에서 301 또는 302 리디렉션 공격

분류에서Dev

How to insert and return the full object in Spring Boot

분류에서Dev

Custom ModRewrite to redirect to controller method

Related 관련 기사

  1. 1

    How to return Controller instead of View in RequestMapping in Spring?

  2. 2

    301 Redirect to a 302 Redirect (SEO implications)

  3. 3

    how to return two lists from controller class in spring mvc

  4. 4

    how to do 301 redirect of the same URL with a difference in hypen

  5. 5

    301 .htacess redirect issue

  6. 6

    Response.Redirect (url)는 firefox 개발자 콘솔에 301과 302를 보여줍니다.

  7. 7

    How to redirect user from controller to another domain

  8. 8

    301 redirect for all get request

  9. 9

    301 Redirect a folder to a single page

  10. 10

    htaccess 301 redirect -- remove a string

  11. 11

    htaccess 301 redirect — remove a path

  12. 12

    Firefox: How to get my home page in new tabs, instead of the recent sites 'tiles' thing :(

  13. 13

    How can I return two values in a controller

  14. 14

    how to put confirm alert in controller and redirect to perticular link if cancel it in yii

  15. 15

    Redirect 301 on changed root name not working

  16. 16

    301 redirect complete url to different extension, BUT with exceptions

  17. 17

    Redirect 301 in htaccess changes the url encoding

  18. 18

    HTACCESS 301 redirect issue with strange url variables

  19. 19

    htaccess redirect 301 https www to non www

  20. 20

    How to send json instead of params in spring test

  21. 21

    How to add a constructor in Controller via Spring

  22. 22

    Spring Security 302 리디렉션

  23. 23

    How to return 404 when resource is not found, instead of HTML

  24. 24

    How to get this Python method to return a string instead of writing it to stdout?

  25. 25

    CodeIgniter, how to return multiple queries from model to controller?

  26. 26

    Vue.js에서 JavaScript로 GET 301/302 응답 처리

  27. 27

    SEO에서 301 또는 302 리디렉션 공격

  28. 28

    How to insert and return the full object in Spring Boot

  29. 29

    Custom ModRewrite to redirect to controller method

뜨겁다태그

보관