getting param value

how to get the  <param-value> from web.xml to a jsp page in struts
snehavinodhanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rrzCommented:
If your web.xml file contains something like
<servlet>
    <servlet-name>test</servlet-name>
    <jsp-file>/test.jsp</jsp-file>
    <init-param>
        <param-name>myParam</param-name>
        <param-value>This is my param value.</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>test</servlet-name>
    <url-pattern>/test.jsp</url-pattern>
</servlet-mapping>

Open in new window

then in your JSP you can use
<%=config.getInitParameter("myParam")%> or <%=getInitParameter("myParam")%> 
or if you are using latest version of JSP  you can use 
${pageContext.servletConfig.getInitParameter("myParam")} 

Open in new window

0
snehavinodhanAuthor Commented:
thanks for this code in jsp......plz help me the same in struts
0
rrzCommented:
I don't use Struts but I think the code would be similar. I could google to see any difference. But before I do that you need to tell us what exactly you want to do. Do you want a param-value accessible  to one JSP or Servlet?  This what I posted above here.  Or do want the param-value accessible to your whole web app? For example in your web.xml file you could have the following.
> <context-param>
>  <param-name>myParamName</param-name>
>  <param-value>myParamValue</param-value>
> </context-param>

Open in new window

0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

snehavinodhanAuthor Commented:
i want the param-value in the web.xml  accessible to the whole web application....
0
rrzCommented:
Ok. You can read
http://www.codejava.net/frameworks/struts/reading-parameters-from-webxml-in-struts2-action-class 
http://www.coderanch.com/t/57641/Struts/read-init-params-Struts-Action 
https://mail-archives.apache.org/mod_mbox/struts-user/200405.mbox/%3C000501c43e51$8c4b3a70$1300a8c0@DOMINIONT%3E   
http://stackoverflow.com/questions/28442772/unable-to-get-init-parameter-from-servlet-context-using-el   
You could use something like the following in your web.xml file.
<context-param>
<param-name>myParam1</param-name>
<param-value>myParamValue1</param-value>
</context-param>

Open in new window

In your JSP use
${initParam['myParam1']} 

Open in new window

0
gurpsbassiCommented:
i want the param-value in the web.xml  accessible to the whole web application....

The key thing you have said here is "whole web application".

If this is your requirement, then you need a servlet context param not a init param.

If you then want to access the context param, you have a handle on the request object in your struts action.
request.getSession().getServletContext().getInitParameter("myParam");

Your requirements are very loose. So its hard to say whether this is the solution you seek.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
snehavinodhanAuthor Commented:
thank you...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.