Seven action instructions of JSP

Keywords: JSP

Seven action instructions of JSP

JSP action instructions are mainly a group of dynamically executed instructions, which are used in the form of tags. Different from compiling commands, action instructions are action scripts at runtime. The seven action instructions of JSP are as follows:
jsp:forward performs page steering and forwards the processing of the request to the next page.
jsp:param is used to pass parameters and must be used with other tags that support parameters.
jsp:include is used to dynamically introduce a JSP page.
jsp:plugin is used to download JavaBean s or applets to the client for execution.
jsp:useBean uses JavaBean.
jsp:setProperty sets the property value of the JavaBean instance.
jsp:getProperty gets the property value of the JavaBean instance.

jsp:forward action instruction case
This action is to realize the jump of the server-side page, that is, forward from the current page to another page, which can be forwarded to a static HTML page, a dynamic JSP page, or a Servlet in the container. In fact, the same request is completed. Therefore, the forwarded request is also effective on the new page. This jump method is called server-side jump, Use jsp;param pass parameters.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
 <!--This action is to jump the server-side page, that is, forward from the current page to another page,
 Can be forwarded to static HTML Pages can also be forwarded to dynamic JSP Page, or forwarded to the container Servlet,
 In fact, the same request was completed, so it was forwarded request The new page is also valid. This jump method is called
 Server side jump,use jsp;param Transfer parameters-->
  This is the home page index.jsp page<br>
  <jsp:forward page = "WEB-INF/page.jsp">
  <jsp:param name="username" value = "wangguodong" />
      <jsp:param name = "password" value = "123456"/>
  </jsp:forward>
  </body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
This is page.jsp page<br>
user name:<%=request.getParameter("username")%><br>
password:<%=request.getParameter("password")%><br>
</body>
</html>

jsp:include action instruction case
The jsp:include instruction tag is used to insert the output content of another resource into the output content of the current JSP page. In fact, it inserts the response content generated by the servlet of the specified page into the corresponding position of the page. This introduction during JSP execution is called dynamic introduction. The action instruction involves two JSP pages, which will be translated into two servlets, and the contents of the two servlets will be merged during execution.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  This is the home page index.jsp <br>
  <!--page Specify the relative and absolute paths to include files
      flush Property specifies when inserting the output of other resources,Will the current JSP The output of the page is refreshed to the client-->
  <jsp:include page = "WEB-INF/page.jsp" flush="true">
  <jsp:param name = "username" value="wang"/>
  <jsp:param name="password" value="123"/>
  </jsp:include>
  </body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
This is page.jsp page<br>
user name:<%=request.getParameter("username")%><br>
password:<%=request.getParameter("password")%><br>
</body>
</html>

jsp:plugin action instruction
The jsp:plugin action instruction dynamically downloads the server-side JavaBean or Java Applet program to the client browser for execution. When the JSP page is responded to the browser for execution, the jsp:plugin will be replaced with object or embed ded tag according to the browser version.

jsp:param action instruction
jsp:param is often used with jsp:include, jsp: forward and jsp: plugin to pass parameter information between pages.

jsp:useBean action instruction
This action is used to instantiate one or more JavaBean components in the JSP page. These instantiated JavaBean components can be called in the JSP page.

jsp:setProperty and jsp:getProperty action instructions
Setting and obtaining JavaBean attributes in JSP pages is more convenient when receiving form parameters.

Posted by erika_web on Wed, 06 Oct 2021 22:34:23 -0700