Java – access request objects from custom JSP Tags

I tried to make a set of custom tags that encapsulate form elements (markup and validation)

There is a way to easily retrieve "out" objects:

JspWriter out = getJspContext().getOut();

But I can't figure out how to get the request object I want to be able to access the submitted form values directly from the tag class so that I can validate each field

Documentation is quite sparse, so I think maybe I can use the jspcontext object to get the request properties in some way But I don't understand the different scope

System.out.println(getJspContext().findAttribute("field1"));

Always print "null"

Enumeration e = getJspContext().getAttributeNamesInScope(1);

Loop through and print out the enumeration, which only gives a list of nonexistent classes:

javax.servlet.jsp.jspOut
javax.servlet.jsp.jspPage
javax.servlet.jsp.jspSession
javax.servlet.jsp.jspApplication
javax.servlet.jsp.jspPageContext
javax.servlet.jsp.jspConfig
javax.servlet.jsp.jspResponse
javax.servlet.jsp.jspRequest

Is this even possible?

If not, can anyone point to the tag library that handles form display and validation? I searched the Internet for hours. It seems that everyone has stopped production and I can't download it Or make better choices for handling forms

Edit: label extension simpletagsupport class

Solution

If your class extends tagsupport, you can access the protected pagecontext variable From there you can retrieve the request object

http://java.sun.com/webservices/docs/1.5/api/javax/servlet/jsp/tagext/TagSupport.html#pageContext

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>