File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSP - Problem in reading InitParameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP - Problem in reading InitParameter" Watch "JSP - Problem in reading InitParameter" New topic
Author

JSP - Problem in reading InitParameter

swathi mani
Greenhorn

Joined: May 06, 2009
Posts: 1
hi,

I trying to read the config parameter for the JSP page; but I am getting value as "null". I do not know why it is not retrieving the param-name "name".
Please help on this

web.xml
-------

<servlet>
<servlet-name>AppView</servlet-name>
<jsp-file>/AppView.jsp</jsp-file>
<init-param>
<param-name>name</param-name>
<param-value>raj</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>AppView</servlet-name>
<url-pattern>/AppView.jsp</url-pattern>
</servlet-mapping>


AppView.jsp
-----------
..
<%! //Init Params
ServletConfig config = null;
String name;
public void jspInit()
{
try{
config = getServletConfig();
name = config.getInitParameter("name");
System.out.println(" Name "+name);
}

}
%>
..


thanks in advance.

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1


Don't use declaration tag fro defining method.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 686



Hi,

May be this will help you...

http://nishanpatel.wordpress.com/2009/04/30/deploymentdescriptor/



Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

config is an implicity variable on jsp. and change your url-pattern name in your web.xml and trigger using it.

Hope this helps
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Are you posted whole code?
where is catch block?



I just commented try and tried your code it is working fine.


Thanks,
Shailesh
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

and please use code tag to post your code. so that we can read your code clearly
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

And Welcome to javaranch. We are happy to have you Here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP - Problem in reading InitParameter