Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get context parameter value in jsp.?

Tags:

java

jsp

  <context-param>
        <param-name>productSearchRPP</param-name>
        <param-value>8</param-value>
    </context-param>

I want to get value of productSearchRPP in products.jsp page

like image 226
Haresh Godhani Avatar asked Dec 26 '12 10:12

Haresh Godhani


People also ask

How do I get context-param?

To access the values from your Java/JSP code, use the following syntax: String value = getServletContext(). getInitParameter("parameterName"); A single <context-param> tag is used for each parameter.

How can we get request parameters in JSP?

In short, to get Request Parameters in a JSP page you should: Create a jsp page that begins with the <%code fragment%> scriptlet. It can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.

What are context parameters?

Context parameters are additional value pairs that are sent to your app in the request URL from the host application. Using context parameters, your apps can selectively alter their behavior based on information provided by the application.

What is <%@ in JSP?

The page directive is used to provide instructions to the container that pertain to the current JSP page. You may code the page directives anywhere in your JSP page. By convention, page directives are coded at the top of the JSP page. Following is the basic syntax of page directive − <%@ page attribute = "value" %>


2 Answers

Even you can try this in your jsp.

ServletContext context = pageContext.getServletContext();
com = context.getInitParameter("com");

and with jstl you can use.

${initParam['theStringIWant']}
like image 166
Ashvin Kanani Avatar answered Oct 09 '22 15:10

Ashvin Kanani


pageContext.getServletContext().getInitParameter("key");

This is how you get context parameter value in JSP. In JSTL you can get it like this

${pageContext.servletContext}

Or

${applicationScope.attributeName}
like image 44
Pradeep Simha Avatar answered Oct 09 '22 14:10

Pradeep Simha