Home  >  Article  >  Java  >  How to implement page jump in java backend

How to implement page jump in java backend

王林
王林Original
2019-12-18 11:28:385335browse

How to implement page jump in java backend

There are two types of page jump categories: redirection and forwarding, namely redirect and forward.

1: Redirect redirect

The first way: the return value in the controller is String

Related free learning video sharing:java Online learning

public String login(HttpServletRequest req, HttpServletResponse resp)
return "redirect:http://localhost:8080/index";

The second way: the return value in the controller is void

public void login(HttpServletRequest req, HttpServletResponse resp)
resp.sendRedirect("http://localhost:8080/index");

The third way: the return value in the controller is ModelAndView

return new ModelAndView("redirect:/toList");

2: Forward forward

For example:

request.getRequestDispatcher("/student_list.jsp").forward(request, response);

Recommended related articles and tutorials: java introductory tutorial

The above is the detailed content of How to implement page jump in java backend. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Java exception typesNext article:Java exception types