wood burning stoves 2.0*
The moose likes JSP and the fly likes JSP Initialization Parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Initialization Parameters" Watch "JSP Initialization Parameters" New topic
Author

JSP Initialization Parameters

Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
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

Joined: Jan 26, 2006
Posts: 169
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>
Tina Jain
Greenhorn

Joined: Mar 17, 2006
Posts: 23
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 ]

If You Cannot Give Anything, At least Give A Smile.
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138
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

Joined: Mar 17, 2006
Posts: 23
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

If a deployment descriptor parameter is to be generally accessible from various parts of a web app, it should be a conext parameter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shadab Ansari
Greenhorn

Joined: Sep 02, 2010
Posts: 1
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Is this legacy code? If not, there should be no Java code in your JSP. You should be accessing such data using the EL.
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

You can use EL in your JSP


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

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

Thanks!


Can you show the code?
Soniya Ahuja
Ranch Hand

Joined: Jul 20, 2008
Posts: 83
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.


SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Initialization Parameters