JSP init
Hi,
I'd like to use init() method like in servlets but problem...
First I guess I have to put that method in a <%!%> section.
If I use a public void init() method there's no problem but I'd like to use jakarta-tomcat config file with the public void init(ServletConfig config) method but it doesn't work because that method is final (cannot override the final method of the same signature declared in class org.apache.jasper.runtime.HttpJspBase. Final methods cannot be overridden.).
Any suggestions?
Thanks
[569 byte] By [
gentyt] at [2007-9-26 3:22:15]

I just tried it. Bummer. I wonder why they did that at Jakarta? Anyway, why do you want to do it? If you can do it in a servlet but not a JSP, why not do it in a servlet? - You're probably doing too much processing in the JSP, which should be used pretty much just for presentation purposes.
I get that kind of requirement implemented this way in JSP code...
<!%
public void jspInit()
{
javax.servlet.ServletConfig servletConfig = getServletConfig();
}
%>
You can get details of such special methods defining the contract between JSP engine and JSP page author in the JSP specification.
I'm working on a web site which use the same XML/XSD/XSL files for internet and intranet but internet and intranet don't have the same presentation so I guess JPSs are better than servlet for that.
Well, I want to use the config file to set the different paths for the files I need, so when I'll change a path I won't have to change all JSPs which need it.
If there's no way to use a such init file, I think I'll write a class with static variables to do it.
gentyt at 2007-6-29 11:39:49 >

thanks neville_sequeira. It's about working.
About working because I've a little problem with Tomcat no parameter where found...
I know they must be in the web.xml file is this syntax invalid
<web-app>
.....
<init-param>
<param-name>
bases
</param-name>
<param-value>
c:\jakarta-tomcat-3.2.1\webapps\netarras\realisation\maquettes\jsp\bases.dat
</param-value>
</init-param>
...
</web-app>
or must I create a new web.xml file in a special directory? (as you can see my jsp path isc:\jakarta-tomcat-3.2.1\webapps\netarras\realisation\maquettes\jsp\ )
help
gentyt at 2007-6-29 11:39:49 >

Have you nested your <init-param> ... </init-param> block inside a <servlet> ... <servlet> block ? You should.
Also, it looks like you will need to use the tags <jsp-file> and <load-on-startup>
Like this...
<servlet>
<servlet-name>bla</servlet-name>
<jsp-file>/bla/bla.jsp</jsp-file>
<init-param>
<param-name>dbpools</param-name>
<param-value>idb access</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Yes I do :
<web-app>
<servlet>
<servlet-name>
process
</servlet-name>
<jsp-file>
/netarras/realisation/maquettes/jsp/process.jsp
</jsp-file>
<init-param>
<param-name>bases</param-name>
<param-value>myPath</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>
Am I allowed to get InitParameter in JSP throw a ServletConfig and getInitParameter() method?
gentyt at 2007-6-29 11:39:49 >

Anyone?please it's urgent
gentyt at 2007-6-29 11:39:49 >

Only if you specifiy a servlet mapping and invoke the JSP via that mapping.
In other words, if I have this in my web.xml...
<servlet>
<servlet-name>initializeJSP</servlet-name>
<jsp-file>/initParamTester.jsp</jsp-file>
<init-param>
<param-name>initParamName</param-name>
<param-value>uncleandaunt</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>initializeJSP</servlet-name>
<url-pattern>/initializeJSP</url-pattern>
</servlet-mapping>
and this in my initParamTester.jsp...
<%!
String initParamValue = "uninitialized";
public void jspInit()
{
javax.servlet.ServletConfig servletConfig = getServletConfig();
initParamValue = servletConfig.getInitParameter("initParamName");
}
%>
Init parameter initParamName has value : <%= initParamValue %>
then when I access the JSP from browser as...
http://belmont:8000/Trials/initializeJSP
on the output page, I see...
Init parameter initParamName has value : uncleandaunt
but when I access the JSP from browser as...
http://belmont:8000/Trials/initParamTester.jsp
on the output page, I see...
Init parameter initParamName has value : null
For the above test, I have used J2EE reference implementation that comes with J2EE SDK 1.3
OK now you've got your 10 Duke Dollars ;o)
first I didn't use mapping, second I entered the base path, I explain my JSP is locate at :
http://palerme:8080/netarras/realisation/maquettes/jsp/process.jsp and I used /netarras/realisation/maquettes/jsp/process.jsp in the jsp-file tag instead of just /netarras/realisation/maquettes/jsp/process.jsp ...
Sorry it was my first try ;o)
Thank you very much neville_sequeira
gentyt at 2007-6-29 11:39:49 >
