• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Initialization using JSP

 
Ravindranath Chowdary
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I want to do servlet-initialization using jsp. For that in my deployment descriptor file I mentioned as following in the <servlet>...

web.xml:-
<servlet>
<servlet-name>MyFirstJSP</servlet-name>
<jsp-file>/hobby.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>ravindranath@pbsihyd.com</param-value>
</init-param>
</servlet>

In the jsp, I am trying to get the value of the email. But, I am getting the value as null.

My jsp code to get the email from the web.xml:-
hobby.jsp:

<%
ServletConfig sconfig = getServletConfig();
String email = sconfig.getInitParameter("email");
%>
<%= email%>

Can you please suggest me what should be done to get the value in the jsp.


Thanks,
Ravindranath.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you mapped "MyFirstJSP" to URL using <servlet-mapping>? also try to access JSP using the same URL pattern you mentioned in web.xml.
 
Ravindranath Chowdary
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prabhu,
Thanks alot. Now, I got email displayed in my page.



Thanks,
Ravindranath.
 
Ravindranath Chowdary
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
Every _jsp.java file has the ServletConfig initialized in the service method (_jspService()) right!. By keeping that in mind I am trying to access the email with out writing the code what I mentioned earlier in my scriptlet...

<%
ServletConfig sconfig = getServletConfig();
String email = sconfig.getInitParameter("email");
%>
I removed the aboce scriptlet from my jsp. I just wrote

<%= config.email%>

During the compilation time of the Servlet it is giving an error as

[javac] D:\Tomcat5.0\work\Catalina\localhost\TestJSP\org\apache\jsp\hobby_jsp.java:59:
cannot resolve symbol
[javac] symbol : variable email
[javac] location: interface javax.servlet.ServletConfig
[javac] out.print( config.email);
[javac] ^
[javac] 1 error


Can you please suggest me how can I resolve the issue.

Thanks,
Ravindranath.
 
Ravindranath Chowdary
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, I got it.

Thanks,
Ravindranath.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!