• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP Initialization Parameters

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
I'm trying to set JSP initialization parameters in the web.xml file
<servlet>
<servlet-name>listener</servlet-name>
<jsp-file>/info.jsp</jsp-file>
<init-param>
<param-name>track</param-name>
<param-value>/track.jsp</param-value>
</init-param>
</servlet>

I, also tried setting the context params:
<context-param>
<param-name>track</param-name>
<param-value>/track.jsp</param-value>
</context-param>

Here is the JSP Code:
info.jsp
--------
Reading param vaue= <%= getServletConfig().getInitParameter("track")%><br>

Reading context param vaue= <%= application.getInitParameter("track")%><br>
The problem is that I'm getting 'null' for both, jsp params and context params....

pls...help...
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thinki go the reply....i missed out the mapping tag...without that it seems things don't work...here is the web.xml file


<servlet>
<servlet-name>listener</servlet-name>
<jsp-file>/info.jsp</jsp-file>
<init-param>
<param-name>track</param-name>
<param-value>/track.jsp</param-value>
</init-param>
</servlet>


<servlet-mapping>
<servlet-name>listener</servlet-name>
<url-pattern>/initJSP</url-pattern>
</servlet-mapping>
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having the same problem I am trying to access the jsp init parameters from the jsp file. And its not working. If somebody know please tell.


Here is the jsp file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
<%@ page import="java.util.*" %>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>AccessGlobalAttrbutes.jsp</TITLE>
</HEAD>
<BODY>
<P>Place content here.</P>




This is a local Parameter: <%= config.getInitParameter("email") %> <br />
This is a local Parameter: <%= pageContext.getServletConfig().getInitParameter("email") %>

<%
Enumeration en = config.getInitParameterNames();
while(en.hasMoreElements()){

%>
<%= "Elements " + en.nextElement() %>

<% } %>

</BODY>
</HTML>






Here the web.xml file.

<servlet>
<servlet-name>AccessGlobalAttrbutes</servlet-name>
<display-name>AccessGlobalAttrbutes</display-name>
<jsp-file>/AccessGlobalAttrbutes.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>localtina@hotmail.com</param-value>
</init-param>
</servlet>


<servlet-mapping>
<servlet-name>AccessGlobalAttrbutes</servlet-name>
<url-pattern>/AccessGlobalAttrbutes</url-pattern>
</servlet-mapping>



in the output is is giving me

Place content here.

This is a local Parameter: null
This is a local Parameter: null


any hint will be of great help.
Have a nice day.
[ October 02, 2006: Message edited by: Tina Jain ]
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tina,

Have you tried the following URL,

http://localhost:8080/test/AccessGlobalAttrbutes

i mean without a .jsp extension in your URL.

This way it works fine for me.

Regards,
Praveen
 
Tina Jain
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pravin,

Thanks for your reply.

If I want to access JSP initializations parameters in a jsp page that how will do it.


your reply
---

Have you tried the following URL,

http://localhost:8080/test/AccessGlobalAttrbutes

i mean without a .jsp extension in your URL.
------


What if I want to access it in the application

Have a Nice Day,
Best Regards,
Tina
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a deployment descriptor parameter is to be generally accessible from various parts of a web app, it should be a conext parameter.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the same problem

The web.xml is :

<servlet>
<servlet-name>TestJspPage</servlet-name>
<jsp-file>/hello.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>TestJspPage</servlet-name>
<url-pattern>/hello.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>city</param-name>
<param-value> New Delhi</param-value>
</context-param>

And I'm trying to use this parameter in my hello.jsp in this way

<%= application.getInitParameter("city") %>

When I'm accessing hello.do
it is giving me null

Can anybody help me out??

Thanks
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this legacy code? If not, there should be no Java code in your JSP. You should be accessing such data using the EL.
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use EL in your JSP
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's OK to get the context initialization parameter through EL, but, if we want to access the JSp initialization parameters through EL, then, How?

Thanks!
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abimaran Kugathasan wrote:if we want to access the JSp initialization parameters through EL, then, How?

Thanks!



Can you show the code?
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use EL implicit objects to access context params
Eg
However, I don't think EL has a way to access JSP initialization parameters directly. You'll have to work around it.
One workaround would be to write a tld - map the getParameterName method and then include this tld in your jsp page and use el to invoke the method.
Someone might be able to suggest a better work around though.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic