Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding jspInit() problem

 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

I'm trying to override jspInit() and than set some context param from there, but doesn't work my way.
here are the code:

DD:


JSP code :


both the outputs from expression are "null" ???

regards,
Rafi
 
Ankit Garg
Sheriff
Posts: 9579
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the name of your JSP file exactly OverridingJspInit.jsp??
 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:Is the name of your JSP file exactly OverridingJspInit.jsp??


Yes, that is the name exactly.
It access jsp file, it prints the line but values from initParameter and context parameter are = null.

regards,
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rafi,

I just copied your code into my tomcat server(5.5) and it is woking well here, this is the output

Email Via ServletContext : r@gmail.com
Email Via ServletConfig : r@gmail.com

Above is example of overriding jspInit() method.

Are you getting the jsp at all on your screen?

Regards,
Frits
 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits Walraven wrote:Hi Rafi,

I just copied your code into my tomcat server(5.5) and it is woking well here, this is the output

Email Via ServletContext : r@gmail.com
Email Via ServletConfig : r@gmail.com

Above is example of overriding jspInit() method.

Are you getting the jsp at all on your screen?

Regards,
Frits


Tomcat Version: Apache Tomcat/5.5.28
File Name : OverridingJspInit [.jsp]
File Location: webapps root [webapps/JSPTest]{D:\tomcat\Tomcat 5.5\webapps\JSPTest\OverridingJspInit}
When I Run It In Browser : { http://localhost:8080/JSPTest/OverridingJspInit.jsp }
***do i have to set any path variable to this 'JSPTest'?****
The Output When I Run:

Email Via ServletContext: null
Email Via ServletConfig: null

Above is example of overriding jspInit() method.

**** only setting and retrieving of the context and init parameters doesn't work **** any guesses, copy of jsp and dd is above.

regards,

Rafi


 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, try this:

http://localhost:8080/JSPTest/OverridingJspInit.do

You have a servlet mapping from OverridingJspInit.do -> >/OverridingJspInit.jsp

What you are doing is going to the page via direct access (like accessing a static html page), so you are not creating a servlet.

Regards,
Frits
 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits Walraven wrote:Ok, try this:

http://localhost:8080/JSPTest/OverridingJspInit.do

You have a servlet mapping from OverridingJspInit.do -> >/OverridingJspInit.jsp

What you are doing is going to the page via direct access (like accessing a static html page), so you are not creating a servlet.

Regards,
Frits


I can't believe it ... i had mapping and i was accessing it differently ... so that was the main reason in my point of view.

but i'm still confused about your statements:

1. Direct Access, like accessing a static html page [as i read in the book, the jsp files are supposed to be stored in webapp root directory and than accessed via http://localhost:8080/webapp-root/jspfile.jsp ....]
I had mapping for the <jsp-file> only because i was overriding jspInit() method, otherwise jsp pages doesn't need a mapping right, hence do you call that direct access???

check this code [same code, just one one expression added] :


check line number#12.

run this jsp file using : http://localhost:8080/JSPTest/OverridingJspInit.jsp
see the output, it will give you null values for the two parameters, but it executes the date perfect ... hence the servlet is created always when the request is made to the jsp page, right?

2. You are not creating servlet ...! how is that possible ... [as i read the moment jsp file is requested ... the container will create a servlet for that particular jsp file ..... even ]

why am i asking these questions are because i will be appearing for the exam soon, so if i could get some valuable information from your side, will definitely benefit me ;-).

thanks for the reply

regards,

Rafi
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rafi,

Yes, you a right (and I just passed SCWCD ) the servlet is made as soon as you request it, but with direct access it doesn't load the init-parameters. The container only knows init parameters of a Servlet, not of a JSP, hence the need of a <servlet> and <servlet-mapping>

Regards,
Frits
 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits Walraven wrote:Rafi,

Yes, you a right (and I just passed SCWCD ) the servlet is made as soon as you request it, but with direct access it doesn't load the init-parameters. The container only knows init parameters of a Servlet, not of a JSP, hence the need of a <servlet> and <servlet-mapping>

Regards,
Frits


Yeah, that is true. I accept the init-param parts.
Anyways, thanks for the help,

regards,

Rafi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic