jsp dynamic tag request forwarding forward

jsp:forward: server jump


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

userbean


//jsp code
<jsp:useBean id="p1" class="cn.itcast.domain.Person" />
//java code
<%
	Person p1 = (Person)pageContext.getAttribute("p1");
	if(p1 == null) {
		p1 = new Person();
        pageContext.setAttribute("p1", p1);
	}
%>

setProperty

The role of the setProperty tag is to set the property value for the Bean. Of course, you must ensure that the Bean already exists before setting the property value.


name is the name in the usebean praperty is the attribute value is the value!

<jsp:useBean id="p1" class="cn.itcast.domain.Person" />
<jsp:setProperty property="sex" value="male" name="p1"/>
//Corresponding Java code
<%
	Person p = (Person)pageContext.getAttribute("p1");
	if(p == null) {
		throw new NullPointerException();
	}
	p.setSex("male");
%>

getProperty:

The role of the getProperty tag is to get the property value of the Bean.


The code in the form.jsp file
    <form action="bean.jsp" method="post">
    	姓名:<input type="text" name="name"/><br/>
    	年龄:<input type="text" name="age"/><br/>
    	性别:<input type="text" name="sex"/><br/>
    	<input type="submit" value="提交"/>
    </form>

Code in the bean.jsp file
<jsp:useBean id="p1" class="cn.itcast.domain.Person" />
<jsp:setProperty property="*" name="p1"/>
<%=p1 %>

The first file submits the attributes, the second file accepts the attributes and sets them to the response person object 




---------------

Subject: .JSTL library


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<hr>
<%
	String [] arr = {"a","b","c"};
	pageContext.setAttribute("arr", arr);
	
%>

Read the length of an array:
	${fn:length(arr) } <br>
Convert to lowercase,:
	${fn:toLowerCase("HELLO") }<br>
Convert to uppercase:
	${fn:toUpperCase("hello") }<br>
Does abc contain a :
	${fn:contains('abc','a') }<br>
Ignore case abc contains A:
	${fn:containsIgnoreCase('abc','A') }<br>
Does the array contain a:
	${fn:contains(arr,'a') }		<br>
Ignore case if the array contains A:
	${fn:containsIgnoreCase(arr,'A') } <br>
Whether to end with the specified character:
	${fn:endsWith('Hello.java','java') }<br>
Whether to start with the specified character:
	${fn:startsWith('Hello','He') } <br>
Specify the index of the character:
	${fn:indexOf('helloworld','wo') }<br>
Concatenate with specified characters:
	${fn:join(arr,'-') } <br>
Replace the specified character: replace the - sign with a + sign						
	${fn:replace("hello-world","-","+") }
Split the string first, and then concatenate it with the specified characters:
	${fn:join(fn:split('a;b;c',';') ,'-') }<br>
Cut String: Display the characters between 6-8
	${fn:substring('0123456789', 6, 9) }	  <br>
	${fn:substring("0123456789", 6, 9)}<br/><!-- 678 -->
	
Cut the string:
	${fn:substring('123456789','5','-1') }	<br>
	${fn:substring("0123456789", 5, -1)}<br/><!-- 56789 -->
	Display the content after the custom character:
${fn:substringAfter("Hello-World", "-")}<br/><!-- World -->
Display the content before the specified character:
${fn:substringBefore("Hello-World", "-")}<br/><!-- Hello -->
remove spaces
${fn:trim("     a b c     ")}<br/><!-- a b c -->
Break free: not parsing HTML language
${fn:escapeXml("<html></html>")}<br/> <!-- <html></html> -->
	
	
	
	
</body>
</html>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325931834&siteId=291194637