반응형

Spring - Page Redirection Example


(원문 위치 : http://www.tutorialspoint.com/spring/spring_page_redirection_example.htm )


이번 강좌는 http request가 다른 page를 전송하기 위한 'redirect'를 사용하는 간단한 웹기반 프로그램을 작성해 본다. 


[21-1] 강좌를 참고하여 프로젝트를 생성한다.


WebController.java:

package com.tutorialspoint.hellowebredirect;


import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;


@Controller

public class WebController {

@RequestMapping(value="/index", method=RequestMethod.GET)

public String index() {

return "index";

}

@RequestMapping(value="/redirect", method=RequestMethod.GET)

public String redirect() {

return "redirect:finalPage";

}

@RequestMapping(value="/finalPage", method=RequestMethod.GET)

public String finalPage() {

return "final";

}

}


index.jsp :

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<html>

<head>

    <title>Spring Page Redirection</title>

</head>

<body>

<h2>Spring Page Redirection</h2>

<p>Click below button to redirect the result to new page</p>

<form:form method="GET" action="/hellowebredirect/redirect">

<table>

    <tr>

    <td>

    <input type="submit" value="Redirect Page"/>

    </td>

    </tr>

</table>  

</form:form>

</body>

</html>


final.jsp :

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<html>

<head>

    <title>Spring Page Redirection</title>

</head>

<body>


<h2>Redirected Page</h2>


</body>

</html>


실행결과는 아래와 같다.


** Srping MVC project에 의해서 자동으로 생성된 페이지











반응형

+ Recent posts