I'm following HFS (p308) and attempted to rustle up a quick test of the code snippet to test servlet init parameters and overiding jspInit. But instead of the email address appearing, I'm getting the following output:
Please email: null
What am I doing wrong?!
My .jsp file (TestInit.jsp) is as follows:
and my web.xml (located in WEB-INF!) is:
I put a servlet-mapping in because I wanted to see if jsp's could be mapped as well, but this doesn't seem to work either (successfully mapped a servlet in earlier chapters!).
So, two questions: 1. Why am I not seeing the email address produced by my jsp? 2. Can you map jsp's to url-patterns?
Any help appreciated! And, yes,I've stop/started tomcat many times and even changed the .jsp to prove it's the active one! Symptom-wise it seems that the init value is not being picked up, but web.xml is correctly in WEB-INF so I see no reason why this doesn't work!
OK, my mistake! 1. Output now correct. 2. servlet-mapping, url-pattern now working for jsp.
My first problem was invoking the .jsp direct. This seems to bypass the use of the DD, hence "email" never gets initialised.
I'd used direct invocation of .jsp because I thought I was having problems using servlet-mapping for this jsp. It turned out that servlet-mapping was occurring, but no params were being initialised. The reason? Because at the time I had left out the "xlmns" bits & pieces (technical term) at the start of the DD. Somewhere along the line, although I had added the namespaces, I never retried the servlet-mapped address having done so. I was still invoking the .jsp directly. :roll:
Having finally retried again using "http://localhost:8080/testJsp/myInit.do" I get the correct output: "Please email: email@example.com"