What is the best way to send parameters to servlets when using the jsp:include statement to embed the servlet output inside of a JSP page?
Created May 4, 2012
Ryan Breidenbach The best way to send parameters using the <jsp:include> action is with the <jsp:param> tag. This would look something like:
<jsp:include page="servletName" ...> <jsp:param name="paramName" value="paramValue"> <jsp:include />
Now, the included servlet can access these parameters the same way it accesses all other parameters: getParameter(String name)
.
The only caveat to this is if the parameter name being used in the <jsp:param> tag is already being used, it will add the new value. Therefore, in order access all the values associated with a parameter name, you will need to use getParameterValues(String name)
. Note: When a value is added to a list of values for a given parameter name using the <jsp:param> tag, the new value becomes the first value in the list.