• 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

passing initial parameters to jsp

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI all
I struck with the passing initial parameters to JSP page on TOMCAT webserver. to pass initial parameter to a servlet can be achieved with the help of web.xml file, but how to pass initial parameters to a JSP page.
thank you
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may write initial parameters in jsp in special tags <%! %>
It calls as in servlet init() method. For fully information see jsp and servlet specification on java.sun.com
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my JSP page is on TOMCAT webserver i want to pass initial parameters to this JSP, to pass initial parameters to servlet we make changes in web.xml file we set the servlet name and initial parameter name, values to it.
but my question is in the same we way how we have done it for servlets can i pass the parameters to JSP page.
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don�t think so, I�m using WL6.0 and when I need to pass initial parameters to jsps I have to write another xml file called weblogic.xml and than I can use:
<jsp-descriptor>
<jsp-param>
<param-name>
jsp param name
</param-name>
<param-value>
my value
</param-value>
</jsp-param>
</jsp-descriptor>
and since I have to write a diferent file to do so, problably yo�ll not be able to do using web.xml, but noticed that I�m not really sure and if you find out a way pls post here that I�d love to learn it.

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You pass init parameter to a JSP the same as a servlet, using the web.xml deployment descriptor. The key is using the <jsp-file> element instead of <servlet-class>:
<servlet>
<servlet-name>foo</servlet-name>
<jsp-file>myFile.jsp</jsp-file>
<init-param>
<param-name>flavor</param-name>
<param-value>vanilla</param-value>
</init-param>
</servlet>
Note, however, that you need to call the JSP by its servlet name, which would be %WEBAPPNAME%/servlet/foo, in the case above. If you don't, the servlet engine will not be aware that you are using the <servlet> element with its init parameters.
You can additionally supply a servlet mapping if you still want to use a "jsp" name:
<servlet-mapping>
<servlet-name>foo</servlet-name>
<url-pattern>myFile.jsp</url-pattern>
</servlet-mapping>
If you've never read the JSP specification or the DTD, it can be of great help to you.

------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
 
Vishnu Murthy
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i tried the following
in web.xml deployment descriptor file i have written as
<servlet>
<servlet-name>RSRemoteAccess</servlet-name>
<jsp-file>RSRemoteAccess.jsp</jsp-file>
<servlet-mapping>
<servlet-name>RSRemoteAccess</servlet-name>
<url-pattern>RSRemoteAccess.jsp</url-pattern>
</servlet-mapping>
<init-param>
<param-name>sqldsn</param-name>
<param-value>coldsql</param-value>
</init-param>
</servlet>
and i am calling this jsp page with url http://machinename ort/mydirectory/RSRemoteAccess.jsp
String param = getInitialParameter("sqldsn);
out.println("parameter is : "+param);
but it is showing retrieved parameter as null
can u pl. tell me how to solve this problem
 
Vishnu Murthy
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Phil
after setting initial parameters in web.xml file when i am trying to invoke JSP with the url http://servarname/examples/servlet/RSRemoteAccess
i am getting the following error
Error: 500
Location: /examples/servlet/RSRemoteAccess
Internal Servlet Error:
java.lang.NullPointerException
at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java, Compiled Code)
my web.xml file is like this..

<servlet>
<servlet-name>RSRemoteAccess</servlet-name>
<jsp-file>RSRemoteAccess.jsp</jsp-file>
<init-param>
<param-name>sqldsn</param-name>
<param-value>coldsql</param-value>
<description>set for checking for the First parameter</description>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RSRemoteAccess</servlet-name>
<url-pattern>RSRemoteAccess.jsp</url-pattern>
</servlet-mapping>
i am not able to solve this
please help me in this matter
thanking you
vishnu
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your only giving half of things here. Your not showing the line the error is occuring on. I'm assuming it's on
String param = getInitialParameter("sqldsn");
out.println("parameter is : "+param);
It looks like your trying to access the method getInitialParameter defined in your JSP page. There isn't one unless you've defined it yourself inside scriptlet. (And your not showing enough of your jsp for me to tell)
However, I believe what you really want is
String param = config.getInitParameter("sqldsn");
out.println("parameter is : "+param);
config is the implicate object reference available in your JSP to access anything you would use ServletConfig in a normal servlet.

------------------
Hope This Helps
Carl Trusiak, SCJP2
[This message has been edited by Carl Trusiak (edited August 07, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic