The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes overriding jspInit() problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "overriding jspInit() problem" Watch "overriding jspInit() problem" New topic
Author

overriding jspInit() problem

Rafi Fareen
Ranch Hand

Joined: Aug 28, 2009
Posts: 75
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
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

Is the name of your JSP file exactly OverridingJspInit.jsp??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rafi Fareen
Ranch Hand

Joined: Aug 28, 2009
Posts: 75
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
Rancher

Joined: Apr 07, 2010
Posts: 1042

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

Joined: Aug 28, 2009
Posts: 75
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
Rancher

Joined: Apr 07, 2010
Posts: 1042

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

Joined: Aug 28, 2009
Posts: 75
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
Rancher

Joined: Apr 07, 2010
Posts: 1042

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

Joined: Aug 28, 2009
Posts: 75
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: overriding jspInit() problem
 
Similar Threads
question--Initializing JSP
Trouble with application attribute / jspInit...
Getting Junk Values While overridding jspInit()
how to get init-param in jsp
JSP init parameters.