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

Initialization Parameter in JSP

 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankur Gargg,
Here is the DD-

URL-
/MyInitParamJsp.jsp
 
Ankur Gargg
Ranch Hand
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramon Valdez
My problem is resolved now. Solution given by Ankur Gargg is correct. Anyways.. thanks for the reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic