| Author |
Initialization Parameter in JSP
|
Astha Sharma
Ranch Hand
Joined: Oct 15, 2011
Posts: 205
|
|
This is my JSP code-
This is my web.xml file-
This JSP page is resulting output as-
Your email id : null
Why is it giving null? Please help...
|
 |
Ankur Gargg
Ranch Hand
Joined: Sep 11, 2011
Posts: 51
|
|
Hi
Please have a look at
http://www.coderanch.com/t/177239/java-Web-Component-SCWCD/certification/init-param-jsp
Regards
Ankur Garg
|
|
 |
Astha Sharma
Ranch Hand
Joined: Oct 15, 2011
Posts: 205
|
|
Thanks for the reply Ankur, but this didn't help. The reason for the same problem was different in that discussion. I m still not getting what is the problem in my JSP?
|
 |
Ankur Gargg
Ranch Hand
Joined: Sep 11, 2011
Posts: 51
|
|
Hi astha
How are you accessing the jsp?
Can you please provide the url?
In case you are accessing it directly using it then implicit mapping of container may come in and not pass the initialization parameters.
It would be better if you can tell me url.Also If you are accessing it directly the please add following
<servlet-mapping>
<servlet-name>MyInitParamJsp</servlet-name>
<url-pattern>url mapping that will satisfy your request</url-pattern>
</servlet-mapping>
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
Astha Sharma wrote:... I m still not getting what is the problem in my JSP?
You have to set the complete name of your JSP file with the extension. And also add the url-mapping to the web.xml as mentioned.
And yes we don't use scriptlets, scriptlet expressions etc... in the JSPs these days.
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
Astha Sharma
Ranch Hand
Joined: Oct 15, 2011
Posts: 205
|
|
Ankur Gargg wrote:
Also If you are accessing it directly the please add following
<servlet-mapping>
<servlet-name>MyInitParamJsp</servlet-name>
<url-pattern>url mapping that will satisfy your request</url-pattern>
</servlet-mapping>
Vijitha Kumara wrote:
And also add the url-mapping to the web.xml as mentioned.
I tried this also. Even on adding url-mapping it is displaying null
Ankur Gargg wrote:
It would be better if you can tell me url.
It is /MyInitParamJsp.jsp
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
Astha Sharma wrote:I tried this also. Even on adding url-mapping it is displaying null
Then what about your value in the <jsp-file> tag? If you have this correctly then it should work unless you are not telling us something else that you have done...
|
 |
Ankur Gargg
Ranch Hand
Joined: Sep 11, 2011
Posts: 51
|
|
Hi Astha
Give me the full web.xml of your code.
and also the url you are using to access the jsp.
|
 |
Astha Sharma
Ranch Hand
Joined: Oct 15, 2011
Posts: 205
|
|
Ankur Gargg,
Here is the DD-
URL-
/MyInitParamJsp.jsp
|
 |
Ankur Gargg
Ranch Hand
Joined: Sep 11, 2011
Posts: 51
|
|
hi..
please change web.xml to this.
<web-app>
<servlet>
<servlet-name>MyInitParamJsp</servlet-name>
<jsp-file>/MyInitParamJsp.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>asthasharma017@gmail.com</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyInitParamJsp</servlet-name>
<url-pattern>/MyInitParamJsp.jsp</url-pattern>
</servlet-mapping>
</web-app>
|
 |
Astha Sharma
Ranch Hand
Joined: Oct 15, 2011
Posts: 205
|
|
I have tried this also. But it is giving 500 error
This is displaying following exception-
javax.servlet.ServletException: missing jspFile
|
 |
Ankur Gargg
Ranch Hand
Joined: Sep 11, 2011
Posts: 51
|
|
hi
can you give the full /URL including the localhost and context part information?
Also can you give me the directory structure you are using?
where is your jsp file placed?
|
 |
Astha Sharma
Ranch Hand
Joined: Oct 15, 2011
Posts: 205
|
|
my jsp file is placed inside a folder InitParamJSP inside webapps folder of tomcat. Tomcat is installed in C drive.
full url is-
http://localhost:1990/InitParamJSP/MyInitParamJsp.jsp
|
 |
Ankur Gargg
Ranch Hand
Joined: Sep 11, 2011
Posts: 51
|
|
Hi
I used the same web.xml as provided by me and the same jsp as provided by you.
Here are the results
Your email id : asthasharma017@gmail.com
I guess you are missing something.Please do a double check.
|
 |
Ramon Valdez
Greenhorn
Joined: Mar 07, 2011
Posts: 2
|
|
I think you should include the folder containing the jsp file in the jsp-file tag as follows:
<jsp-file>/InitParamJSP/MyInitParamJsp.jsp</jsp-file>
The use of config.getInitParameter is ok.
I hope you can solve your problem.
|
 |
Astha Sharma
Ranch Hand
Joined: Oct 15, 2011
Posts: 205
|
|
Ramon Valdez
My problem is resolved now. Solution given by Ankur Gargg is correct. Anyways.. thanks for the reply.
|
 |
 |
|
|
subject: Initialization Parameter in JSP
|
|
|