This article aims to correct some incorrect articles on the Internet!
Development steps:
First, create a class:
Inherit bodytagsupport
Then set the field generation Set Method
Class:
Package Org. pan. tags; import Java. io. ioexception; import Java. io. printwriter; import javax. servlet. HTTP. httpservletrequest; import javax. servlet. HTTP. httpservletresponse; import javax. servlet. HTTP. httpsession; import javax. servlet. JSP. jspexception; import javax. servlet. JSP. tagext. bodytagsupport; public class sessionproperty extends bodytagsupport {Private Static final long serialversionuid = 1l; private string value; // The Public void setvalue (string value) {This. value = value;} Public String getvalue () {return value;} @ overridepublic int doendtag () throws jspexception {// todo auto-generated method stubreturn super. doendtag () ;}@ overridepublic int dostarttag () throws jspexception {system. out. println ("OK"); httpservletrequest request = (httpservletrequest) pagecontext. getrequest (); httpsession session = request. getsession (); object = session. getattribute (value); If (Object = NULL) return eval_page; If (Object instanceof string) {try {pagecontext. getout (). write (object. tostring ();} catch (ioexception e) {// todo auto-generated catch blocke. printstacktrace () ;}} return Super. dostarttag ();}}
Note:
The output content must be:
pageContext.getOut().write(object.toString());
TLD Configuration:
Create a TLD file that needs to be placed in the WEB-INF
<?xml version="1.0" encoding="UTF-8" ?><taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"version="2.0"><description>JSTL 1.1 core library</description><display-name>JSTL core</display-name><tlib-version>1.1</tlib-version><short-name>w</short-name><uri>http:/winter.baletu.com/</uri><tag><description>Obtained from the session attribute</description><name>property</name><tag-class>org.pan.tags.SessionProperty</tag-class><body-content>JSP</body-content><attribute><name>value</name><required>true</required><rtexprvalue>false</rtexprvalue></attribute></tag></taglib>