This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Initialization Parameters

 
Reema Patel
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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>
 
Tina Jain
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Praveen Babu
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Shadab Ansari
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use EL in your JSP
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Soniya Ahuja
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic