. Parameter tag."/> . Parameter tag.">

Home  >  Article  >  Java  >  How to use jsp tags

How to use jsp tags

(*-*)浩
(*-*)浩Original
2019-06-01 14:52:273039browse

Learning jsp has to learn jsp tags. Generally speaking, for a jsp developer, it can be understood that the less java code appears in the jsp page, the better the mastery of jsp, and the important way to replace the java code is Just use jsp tags.

How to use jsp tags

Classification of jsp tags:

Built-in tags (action tags): No need to import tags in the jsp page

jstl tag: Tags need to be imported into the jsp page

Custom tags: Developers define it themselves, tags need to be imported into the jsp page

Built-in tags (action tags):

Forward tag:

语法:<jsp:forward page="/MyJsp001.jsp"></jsp:forward>
相当于java代码:request.getRequestDispatcher("/MyJsp001.jsp?name=jxf").forward(request, response);
注意:但是java代码的转发可以通过url带参数的方式进行传递参数,而转发标签需要借助于下面的<jsp:param>标签实现参数传递

Parameter tag:

语法:  <jsp:param value="jxf" name="name"/> <%-- 传递一个名为name,值为jxf的参数,参数一般作为其他标签的子标签使用--%>

结合<jsp:forward>标签用法:
<jsp:forward page="/MyJsp001.jsp">
  <jsp:param value="jxf" name="name"/>
</jsp:forward>

Include tags:

语法:
<jsp:include page="/MyJsp001.jsp">
        <jsp:param value="jxf" name="name"/><%--可以将参数传递给包含进来的页面--%>
</jsp:include>

jsp中还有一个包含指令,也是将一个页面包含另外的页面

他们之间的区别:

  1、首先是语法不同
    <jsp:include page="/MyJsp001.jsp">
    <%@inclue file="被包含的页面"%>
  2、<jsp:include>可以传递参数,<%@inclue%>不可以
  3、<jsp:include>:包含页面与被包含页面分别编译为两个java源文件,在运行时引用
     <%@inclue%>:包含页面与被包含页面合并编译为一个java源文件

jstl tags:

jstl标签的类型:
  核心标签库 (c标签库)//这里主要使用c标签库,因为用的真的很多
  国际化标签(fmt标签库)
  EL函数库(fn函数库)
  xml标签库(x标签库)//一般不用该库,这属于数据操作,而数据操作应于dao层中,jsp页面主要用于展示数据
  sql标签库(sql标签库)//与xml标签库类似,不应在jsp页面中操作数据(当然他们是可以在jsp页面写)

Custom tags:

When JSTL tags When the library can no longer meet our needs, we need to develop custom tags ourselves to meet our needs. The custom tag is actually an ordinary java class that inherits the SimpleTagSupport class.

The above is the detailed content of How to use jsp tags. 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:How to run jsp codeNext article:How to run jsp code