Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access request in JspTags?

Tags:

java

jsp

jsp-tags

I want to call request.getContextPath() inside a JSP tag which extends SimpleTagSupport, is there any way to do it?

like image 264
Brodie Avatar asked Jan 20 '10 03:01

Brodie


People also ask

How to use request in JSP?

The JSP request is an implicit object of type HttpServletRequest i.e. created for each jsp request by the web container. It can be used to get request information such as parameter, header information, remote address, server name, server port, content type, character encoding etc.

How to define request in JSP?

The JSP request can be defined as an implicit object is an instance of "HttpServletRequest" and is formed for all JSP requests through the web container. This JSP request gets request information like a parameter, remote address, header information, server port, server name, character encoding, content type, etc.

Which is used to get the name and print in JSP string name?

getQueryString() – Used for getting the query string associated to the JSP page URL.


1 Answers

First get the PageContext by the inherited SimpleTagSupport#getJspContext() and then get the HttpServletRequest by PageContext#getRequest().

PageContext pageContext = (PageContext) getJspContext();  
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();  
like image 77
BalusC Avatar answered Oct 08 '22 09:10

BalusC