Introduction to JSP and basic grammar of JSP

Disadvantages of Servlet development

  • Static HTML is mixed with dynamic Java code, which is difficult to maintain
  • Servlet uses the out.println() statement to output, and the development efficiency is low
  • Eclipse is difficult to find errors in the development process, and debugging is difficult

JSP introduction

  • JSP is called java Sever Pages, Java server page
  • JSP is a J2EE functional module, executed by the Web server (such as Tomcat)
  • The role of JSP is to reduce the difficulty of developing dynamic web pages

Features of JSP

  • JSP is easy to use
  • JSP separates HTML and Java code to reduce the difficulty of development
  • The essence of JSP is Servlet

JSP operating requirements

  • Working Tomcat
  • The extension of all JSP pages is .jsp
  • JSP pages should be placed in the web application directory

JSP execution process

details

JSP basic syntax

  • JSP code block

JSP code block is used to embed JAVA code in JSP, the syntax of the code block is: <%javacode%>, for example:

<%System.out.println("hello,world")%>
  • JSP declaration building block

JSP declaration building block is used to declare variables and methods, the syntax is <%! Declaration statement%>, for example:

<%! 
public int add(int a, int b){
    return a+b;
}
%>
  • JSP output instructions

The JSP output instruction is used to display the output result of the java code in the JSP page, the syntax is <%=java code%>, for example

<%="<b>"+name+"</b>"%>
  • JSP processing instructions

The JSP processing instruction is used to provide auxiliary information during the execution of the JSP. The syntax of the JSP processing instruction is: <%@ jsp instruction%>

<%@ page import="java.util"%> //导包操作
常用的处理指令
<% @ page %> //定义当前JSP页面的全局设置
<% @ include %> //将其他JSP页面和当前JSP页面合并
<% @ taglib %> //引入JSP标签库
  • Comments in JSP
<%--注释--> jsp注释
//、/*...*/ java注释
<!--html--> html注释

 

Guess you like

Origin blog.csdn.net/qq_41459262/article/details/111061885
jsp
Recommended