-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c539134
commit cfb31e9
Showing
2 changed files
with
38 additions
and
13 deletions.
There are no files selected for viewing
19 changes: 6 additions & 13 deletions
19
mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JspView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
mvc/src/main/java/webmvc/org/springframework/web/servlet/view/RedirectView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package webmvc.org.springframework.web.servlet.view; | ||
|
||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import webmvc.org.springframework.web.servlet.View; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public abstract class RedirectView implements View { | ||
|
||
public static final String REDIRECT_PREFIX = "redirect:"; | ||
|
||
protected final String viewName; | ||
|
||
protected RedirectView(final String viewName) { | ||
this.viewName = viewName; | ||
} | ||
|
||
@Override | ||
public void render(final Map<String, ?> model, final HttpServletRequest request, final HttpServletResponse response) throws Exception { | ||
if (viewName.startsWith(REDIRECT_PREFIX)) { | ||
response.sendRedirect(viewName.substring(REDIRECT_PREFIX.length())); | ||
return; | ||
} | ||
renderWithoutRedirect(model, request, response); | ||
} | ||
|
||
protected abstract void renderWithoutRedirect(final Map<String, ?> model, final HttpServletRequest request, | ||
final HttpServletResponse response) throws ServletException, IOException; | ||
} |