• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to initialize jsp init parameters

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to send some init paramets to my InitJsp file. I am not able to do it in the Jsp as mentioned in HeadFirst servlets and Jsp book. I will just write the code for more clarificatio.

In the web.xml

<servlet>
<servlet-name>MyJsp</servlet-name>
<jsp-file>/InitJsp.jsp</jsp-file>

<init-param>
<param-name>email</param-name>
<param-value>abc@acs.co.in</param-value>
</init-param>
</servlet>

And in the Jsp file

<%! public void jspInit(){
ServletConfig sConfig = getServletConfig();
String mailId = sConfig.getInitParameter("email");
System.out.println("The mail id is "+mailId);
%>

Kindly let me know how to make it work. Also what is the servlet name i should give in <servlet-name> tag in the DD.

Thanks and Regards,
Pradeep
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your best bet would be to move all that logic into a Servlet and leave Java code out of the JSPs.
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pradeep,

i think your <url-pattern> element in <servlet-mapping> element is mapping some other url. if you are getting null for that.

let me know what output you are getting in the console.

do as per what Bear Bibeault said "avoid using scriptlet in jsp".

do reply.........
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The container automatically creates a url pattern that matches the name of the JSP file for you. It may be that the url-pattern generated by the container is overriding yours.

Try a different url pattern; one that doesn't match the name of the file.
For example: "InitJsp" and see if that works.


+1 for Bear's advice to move this logic out of JSPs.
But out of curiosity, I'd try to see if I could get this to work.
 
Pradeep Kumar
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ranchers,
The code works fine. The mistake i did was i did not put the <servlet-mapping> tag and sub tags. It works fine. Thanks ranchers. :-)
 
Look! I laid an egg! Why does it smell like that? Tiny ad, does this smell weird to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic