Create a simple jsp tag today !! Get your own IP Address
First, create a class that implements the Tag interface and inherit the TagSupport class.
Then rewrite the doStartTag method in it, and write here to get your own id;
Because the request and out methods must be used
HttpServletRequest request = (HttpServletRequest) pageContext. getRequest (); // get it through pageContext
JspWriter out = pageContext. getOut ();
String id = request. getRemoteAddr (); // obtain your own ip number;
Out. print (ip); // here or there is an exception, you can handle it.
In this way, this class is complete. Next, create a tld file to describe the tag processing class.
(Put in the WEB-INF folder)
(C: \ apache-tomcat-6.0.18 \ webapps \ examples \ WEB-INF \ jsp2)
A template is required for writing a file, which needs to be searched in the preceding address,
<? 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> A tag library exercising SimpleTag handlers. </description> // describes the file.
<Tlib-version> 1.0 </tlib-version> // version
<Short-name> hbsi </short-name> // The prefix value of the jsp tag.
<Uri> http://www.software8.co </uri> // The uri value of the jsp tag
<Tag>
<Name> viewIP </name> // name the tag implementation class and wait for the call.
<Tag-class> com. hbsi. web. tag. ViewIPTag </tag-class> // location of the tag implementation class
<Body-content> empty </body-content> // The content of <viewIp> is empty </viewIp>
</Tag>
</Taglib> www.2cto.com
This allows you to write a jsp file.
First, write the command to write the tag created by yourself.
<% Taglib uri = "http://www.software8.co" prefix = "hbsi" %>
<Body>
Your IP address is: <viewIP/>
</Body>