File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP - Problem in reading InitParameter

 
swathi mani
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2906
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Don't use declaration tag fro defining method.
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi,

May be this will help you...

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

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 368
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you posted whole code?
where is catch block?



I just commented try and tried your code it is working fine.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and please use code tag to post your code. so that we can read your code clearly
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to javaranch. We are happy to have you Here
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic