jsp standard tag

1. userBean usage

Equivalent to instantiated class

<jsp:useBean id="" beanName=""  type=""  class="" scope="">
  • id refers to the object name
  • class refers to the class name. When creating a user, the fully qualified name (package name + class name)
  • type refers to the type. When calling an object, you can use abstract classification or interface
  • scope refers to the scope (page * request session application)

 2. Usage of setProperty and getProperty

They are used to set and fetch values ​​for userBean respectively.

setProperty:

 <jsp:setProperty  name=""  property=""  value="">

getProperty:

    <jsp:getProperty property="" name=""/>
  • name:useBean 的id
  • property: property name (note that it must be consistent with the property name in the entity class)
  • value: attribute value

3. The matching use of include and param

index interface:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
	    <h1>这是主页</h1>
	<jsp:include page="login.jsp">
		<jsp:param value="phone" name="good"/>
	</jsp:include>
	<jsp:include page="login.jsp">
		<jsp:param value="car" name="good"/>
	</jsp:include>
	<jsp:include page="login.jsp">
		<jsp:param value="home" name="good"/>
	</jsp:include>

login interface:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
		String str=request.getParameter("good");
		if("phone".equals(str)){
			str="手机急么便宜,还不快入手?";
		}
		if("car".equals(str)){
			str="你还在挤公交吗,你还在因为上班不方便而烦恼,快入店来看看吧!";
		}
		if("home".equals(str)){
			str="房价大跌,现在不出手,啥时候出手?";
		}
	%>
		<h1 id="h1"><%=str%></h1>
</body>
</html>

 The page shows:

4. jsp forwarding

It is consistent with the effect of forwarding in Java.

<jsp:forward page=""></jsp:forward>

 page refers to the jump interface.

5. The use of web.xml

When we create a project, check the following content in the following interface, and the generated project will automatically create a web.xml file

It is used to specify the initial interface for project opening.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://xmlns.jcp.org/xml/ns/javaee"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
	id="WebApp_ID" version="4.0">
	<display-name>web05</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app> 

 The above is the content of the file. <welcome-file>interface path</welcome-file> is to specify the initial jump interface. If there is no first interface, it will go down until it finds a valid interface. The default is the jump path of index.hmtl.

 Set the initial location to login.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>web13</display-name>
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Note: You must restart the server after modifying web.xml.

 

Guess you like

Origin blog.csdn.net/m0_67376124/article/details/124136888