Contact Us
  
 
 
    SearchSearch   RegisterRegister   Log inLog in 

How can i use ServletConfig getServletConfig in struts

How can i use ServletConfig getServletConfig in struts

 
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans
View previous topic :: View next topic  
Author Message
juniormember



Joined: 28 Jun 2008
Posts: 154

PostPosted: Thu Nov 20, 2008 10:40 am    Post subject: How can i use ServletConfig getServletConfig in struts Reply with quote

Hi

I want to use ServletConfig getServletConfig in action class of struts. and get all param value from web.xml

Quote:
<init-param>
<param-name>paramName</param-name>
<param-value>value</param-value>
</init-param>


i want to use getServlet().getServletConfig(); in struts and want to get value of paramName of init-param tag
Back to top
View user's profile Send private message
javatech



Joined: 19 Jan 2007
Posts: 39

PostPosted: Fri Nov 21, 2008 7:19 am    Post subject: Reply with quote

To use getServletConfig in struts you have to first define init-param in action servlet tag of web.xml.

web.xml file

Code:
<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
   <param-name>application</param-name>
   <param-value>app_resources</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
   <init-param>
<param-name>paramName</param-name>
<param-value>value</param-value>
</init-param>
</servlet>


in execute method of action class
Code:

public ActionForward execute(
         ActionMapping mapping,
         ActionForm form,
         HttpServletRequest request,
         HttpServletResponse response) throws Exception {
               
         DynaActionForm blankForm= (DynaActionForm) form;
         blankForm.initialize(mapping);   
         
         ServletConfig sc=getServlet().getServletConfig();
         String sInitParam=(String)sc.getInitParameter("paramName");
         
         System.out.println("sInitParam :"+sInitParam);
         
         return (mapping.findForward("success"));
   }
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans All times are GMT
Page 1 of 1

 
Jump to:  
  Quick Post a Reply Topic
     
  Name (required)  
     
  Email Address (will not be published) (required)  
     
  Subject of topic (required)  
     
   
     
   
     
  Advertisement  
     
 
     


  More Links  
 
JSP Introduction
JSP Setup
Simple JSP Example
JSP Variable
Array Declaration in JSP
JSP Forms and User Input
Form Validation
JSP Cookies
JSP Session Object
Loop, content collection, iterator, conditional check in JSP
JSP Application Object
JSP Include
JSP Response Object
JSP Request Object
JSP Error Handling
JSP File Handling Object
JSP Action Tag
JSP Implicit Objects
JSP Declaration
JSP Directive
JDBC Introduction
JDBC Driver
JDBC Connection
JDBC Prepared/Statement
JDBC ResultSet
JDBC Close Connection object
JDBC Insert
JDBC Display Records
JDBC Update
JDBC Delete
JDBC Sorting
JDBC Query
JDBC Exception
JDBC Add Batch
JDBC Transaction/RollBack