This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
master stewards:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
garden masters:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
gardeners:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

how to get init-param in jsp

 
pioneer
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to get init-param in jsp. please tell me how to get it?



From above code you can see that I tried two ways to get init-param without
success ,I only get nulls .



best regards,
omi
 
pioneer
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try with application.getInitParameter(" ")

Thanks, Naveen.
 
nav katoch
pioneer
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Disregard the contents of the previous post. Try this way:-

<%! String emailHost = null;
String webMaster = null;
public void jspInit() {
ServletConfig config = getServletConfig();
emailHost = config.getInitParameter("emailHost");
webMaster = config.getInitParameter("webMaster");
}
%>
 
pioneer
Posts: 332
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to remove this line from DD:
<servlet-class>TestServlet</servlet-class>
 
Bobby Sharma
pioneer
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by n katoch:
Disregard the contents of the previous post. Try this way:-

<%! String emailHost = null;
String webMaster = null;
public void jspInit() {
ServletConfig config = getServletConfig();
emailHost = config.getInitParameter("emailHost");
webMaster = config.getInitParameter("webMaster");
}
%>



You did the same thing I did ,Please give a second thought of my post.
Declaring variable outside the jspInit method doesn't change the output because we have to set attribute inside the method.
It's not working.

best regards,
omi
 
Bobby Sharma
pioneer
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by John Stone:
try to remove this line from DD:
<servlet-class>TestServlet</servlet-class>



LOL,what made you think if I remove the line ,it will be fine.

My friend,It will get bigger problem as big fat null pointer exception.

best regards,
omi
 
Bobby Sharma
pioneer
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main problem is getInitParameter() does not get parameter for me,
neither as stand-alone nor inside the method.

best regards,
omi
 
John Stone
pioneer
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


LOL,what made you think if I remove the line ,it will be fine.


The fact, that you have both <jsp-file> and <servlet-class> used in one <servlet> element.
 
Bobby Sharma
pioneer
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So any idea? why I am getting nulls?

best regards,
omi
 
John Stone
pioneer
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What URL are you typing in address bar?
/Test.jsp
or
/Hobby.do?
 
John Stone
pioneer
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
*.jsp is implicitly mapped to org.apache.jasper.servlet.JspServlet, so if you are writing .jsp in address bar, that could be the reason.

from http://faq.javaranch.com/view?InvokerServlet
 
Bobby Sharma
pioneer
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by John Stone:
What URL are you typing in address bar?
/Test.jsp
or
/Hobby.do?



I am trying to access /Hobby.do via form.

forget my problem, the real question is how to access init-param in jsp?
(not context-param)

applicaion.getInItParameter() is for context-param so what for init-param?

best regards,
omi
[ May 23, 2008: Message edited by: omi sharma ]
 
nav katoch
pioneer
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
config
 
Bobby Sharma
pioneer
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by n katoch:
config



Yea that's for init-param but the funny thing is it is also getting null
like others. LOL

But after setting deployment descriptor according to this code , it's working fine.



Actually init-param is not for jsp it's for servlet for jsp we use
context-param like a charm.

John isn't that the same you were trying tell me?

thanks guys for replies

best regards,
omi
[ May 23, 2008: Message edited by: omi sharma ]
 
John Stone
pioneer
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I took your code, removed <servlet-class> element, accessed the page via /Hobby.do and I can see init params.





output:
 
Bobby Sharma
pioneer
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LOL,I think we both were posting at the same time

thanks John

best regards,
omi
[ May 23, 2008: Message edited by: omi sharma ]
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Omi,

I feel that your statement "Actually init-param is not for jsp it's for servlet for jsp we use context-param like a charm" is "wrong".

Jsp is nothing but finally Servlet. We can also set "init-param" to JSP. Your solution of "<context-param>" is just alternate solution but you didn't fix the root cause.

John was right, actual problem is we can't have both "<jsp-file>" and "<servlet-class>" tag, at any time we can have only "<jsp-file>" or <servlet-class>" tag.

I would request you to check the first version of the code by removing the "<servlet-class>" tag.

Thanks.

Vijay Bheemineni.
 
Bobby Sharma
pioneer
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Vijay Bharghav bheemineni:
Hi Omi,

I feel that your statement "Actually init-param is not for jsp it's for servlet for jsp we use context-param like a charm" is "wrong".


John was right, actual problem is we can't have both "<jsp-file>" and "<servlet-class>" tag, at any time we can have only "<jsp-file>" or <servlet-class>" tag.


I would request you to check the first version of the code by removing the "<servlet-class>" tag.



Well my dear ,jsp is servlet for container not for client.
If jsp is really servlet for client ,then please tell me why do we need
to use <jsp-file> element in DD?


Yes , I know John was right.I did not know the whole story because I had
form-parameters to access via servlet and then process it in jsp and a model java class.When I tried to remove <servlet-class> I got null-pointer exception so that time I thought what was he talking about.Later I knew what did he mean.

I already solved my problem. Thank you for reply.

best regards,
omi
[ May 23, 2008: Message edited by: omi sharma ]
 
pioneer
Posts: 55
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, servlet-class must be removed. You either have the servlet from servlet-class, or the servlet generated by the jsp-file.

It shoud work:
<% out.print(pageContext.getServletConfig().getInitParameter("name")); %>

ps: in EL you can't get them.
 
I do some of my very best work in water. Like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!