Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Configuring JSP init parameters

 
Abhishek Jain
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I am screwed with a problem where I wana to read init-param from jsp

JSP LOCATION :-
/webapps/JSPCounter/JSPCounter.jsp

Web.xml Contents :-
<servlet>
<servlet-name>JSPCounter</servlet-name>
<jsp-file>/JSPCounter.jsp</jsp-file>
<init-param>
<param-name>myID</param-name>
<param-value>abhi_svits@yahoo.co.in</param-value>
</init-param>
</servlet>

Overriden init method :-

public void jspInit(){
ServletConfig scg=getServletConfig();
String myID=scg.getInitParameter("myID");
System.out.println(myID);
ServletContext scx=getServletContext();
scx.setAttribute("myID",myID);
}

when i am using this code its giving me null value ???

Regards
Abhishek
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try to define the servlet mapping for this servlet. In your case, you can define the mapping as follows:



Hopefully it works.
 
Abhishek Jain
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eddy

Still its not working

Regards
Abhishek
 
Raghu Shree
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abhishek,
Your code is perfectly legal. No error in your code. I think there is some configuration problem. Check your web.xml file for servlet configuration and servlet mapping. If you would change in your web.xml just restart the server and try it in browser. Hope it will helps you. If you have same problem again give me your web.xml file.
 
Abhishek Jain
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raghu,

FYI,
location :- webapps\JspCounter\web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>JSPCounter</servlet-name>
<jsp-file>/JSPCounter.jsp</jsp-file>
<init-param>
<param-name>myID</param-name>
<param-value>abhi_svits@yahoo.co.in</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JSPCounter</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
</web-app>

Regards
Abhi
 
Raghu Shree
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abishek,
Could you please verify the web.xml is available in webapps/JspCounter/WEB-INF/web.xml.
[ October 18, 2005: Message edited by: Raghu Shree ]
 
Abhishek Jain
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raghu

I was so stupid yaar ........

Yup finally it worked CREDIT TO U ONLY
can I have ur mail ID if u like...
It would be g8 having a friend like U

Thnkx a LOT
Regards
Abhishek
 
Raghu Shree
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abishek,
Sure. jayraghu04@gmail.com. This is my mail Id.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic