How to log exception from a struts action class

Hi guys,
I am recoding my application to use the strut framework. There's one small thing i wonder is that how i can log an exception arrise in an action class. In my original servlet, wherever an exception arise, i use:
catch(Exception e)
         getServletContext().log("User enter an invalid date");
         throw e;
      }However, when i move this servlet into a action class, the getServletContext method doesnt work anymore. I thought action is a child of httpServlet but since getServletContext is not available in action, then how can i log the error?
Hope to get some help
Message was edited by:
lnthai2002

Hi guys,
I am recoding my application to use the strut
framework. There's one small thing i wonder is that
how i can log an exception arrise in an action class.
In my original servlet, wherever an exception arise,
i use:
catch(Exception e)
getServletContext().log("User enter an invalid
valid date");
         throw e;
      }However, when i move this servlet into a action
class, the getServletContext method doesnt work
anymore. I thought action is a child of httpServlet
but since getServletContext is not available in
action, then how can i log the error?
Hope to get some help
Message was edited by:
lnthai2002Action class is just a POJO and works a handler of your request. ActionServlet invoke your Action class based on the action you call in your URL. When you are usign the Struts why do you need your Original Servel, use the ActionServlet and if required you can extend it and create your own servlet

Similar Messages

  • How to send List from jsp to action class

    hi,
    i m fetching list from database and showing to jsp as follows:
    user can update that list i need to collect that updated list in next action class but i m not able to do that. can anybody suggest me any solution the code i m using is as follows:
    <html:form action="/myUpdate">
    <table>
    <tr>
         <td>
              <label><input type="text" property="name" name="name" value=""/></label>
         </td>
    </tr>
    <logic:iterate id="address" name="info" property="addressList" indexId="rowindex">
         <tr>
         <td>
         <input type="text" value="" name="address[<bean:write name="rowindex"/>].houseno" />
         </td>
         <td>
         <input type="text" value="" name="address[<bean:write name="rowindex"/>].roadname" />
         </td>
         <td>
         <input type="text" value="" name="address[<bean:write name="rowindex"/>].city" />
         </td>
         <td>
         <input type="text" value="" name="address[<bean:write name="rowindex"/>].state" />
         </td>
         <td>
         <input type="text" value="" name="address[<bean:write name="rowindex"/>].country" />
         </td>
         </tr>
         </logic:iterate>
    <tr>
         <html:submit/>
    </tr>
    </table>
    </html:form>
    here in privious action i m settting bean object in session with name 'info'. it is fetching data and disply it correctly but when i m trying to get this updated data in myUpdate action i m not getting list element.

    --------------- MyBean.java----------------------
    package form;
    import java.util.Iterator;
    import java.util.List;
    import javax.servlet.http.HttpServletRequest;
    import org.apache.log4j.Logger;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    * @author Sushant.Raut
    public class MyBean extends ActionForm {
         Logger log = Logger.getLogger(this.getClass());
         /* (non-Javadoc)
          * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
         @Override
         public void reset(ActionMapping mapping, HttpServletRequest request) {
              // TODO Auto-generated method stub
              super.reset(mapping, request);
              this.name = "";
         public String toString()
              System.out.println("name : " + this.name );
              for(Iterator<Address> iterator = addressList.iterator(); iterator.hasNext();)
                   Address address = (Address)iterator.next();
                   System.out.println("city : " + address.getCity());
              return null;
         private static final long serialVersionUID = 1L;
         private String name;
         private List<Address> addressList;
          * @return the names
         public MyBean()
              log.info("Bean Construtor is called.");
              System.out.println("MyBean:::::constructor is called.");
         public String getName() {
              log.info("Bean getName() is called");
              return name;
          * @param names the names to set
         public void setName(String name) {
              this.name = name;
              log.info("Bean setName() is called");
          * @return the address
         public List<Address> getAddressList() {
              log.info("Bean getAddressList() is called");
              return addressList;
          * @param address the address to set
         public void setAddressList(List<Address> address) {
              log.info("Bean setAddressList() is called");
              this.addressList = address;
         public Address getAddress(int index)
              log.info("Bean getAddress(int index) is called");
              while(index >= addressList.size())
                   addressList.add(new Address());
              return this.addressList.get(index);
         public void setAddress(int index, Address address)
              log.info("Bean setAddress(int index, Address address)) is called");
              this.addressList.add(index, address);
    }------------- Address.java------------
    package form;
    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts.action.ActionMapping;
    * @author Sushant.Raut
    public class Address {
         private String houseno;
         private String roadname;
         private String city;
         private String state;
         private String country;
         public Address(){}
          * @return the houseno
         public String getHouseno() {
              return houseno;
          * @param houseno the houseno to set
         public void setHouseno(String houseno) {
              this.houseno = houseno;
          * @return the roadname
         public String getRoadname() {
              return roadname;
          * @param roadname the roadname to set
         public void setRoadname(String roadname) {
              this.roadname = roadname;
          * @return the city
         public String getCity() {
              return city;
          * @param city the city to set
         public void setCity(String city) {
              this.city = city;
          * @return the state
         public String getState() {
              return state;
          * @param state the state to set
         public void setState(String state) {
              this.state = state;
          * @return the country
         public String getCountry() {
              return country;
          * @param country the country to set
         public void setCountry(String country) {
              this.country = country;
         public void reset(ActionMapping mapping, HttpServletRequest request)
              this.city = "";
              this.country = "";
              this.houseno = "";
              this.roadname = "";
              this.state = "";
    }------ MyAction.java------
    package action;
    import java.util.ArrayList;
    import java.util.List;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.log4j.Logger;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import form.Address;
    import form.MyBean;
    * @author Sushant.Raut
    public class MyAction extends Action {
         Logger log = Logger.getLogger(this.getClass());
         public ActionForward execute(ActionMapping mapping, ActionForm form,
                   HttpServletRequest request, HttpServletResponse response)throws Exception{
              MyBean myBean = new MyBean();
              log.info("Bean is Initialised.");
              String name = "sushant";
              Address address = new Address();
              address.setCity("city1");
              address.setCountry("India");
              address.setHouseno("1111");
              address.setRoadname("xyz Road");
              address.setState("MH");
              Address address1 = new Address();
              address1.setCity("Hyderabad");
              address1.setCountry("India");
              address1.setHouseno("2222");
              address1.setRoadname("ABC Road");
              address1.setState("AP");
              List<Address> addressSet = new ArrayList<Address>();
              addressSet.add(address);
              addressSet.add(address1);
              myBean.setName(name);
              myBean.setAddressList(addressSet);
              request.getSession().setAttribute("info", myBean);
              log.info("Bean is bound to session.");
              System.out.println("MyBean object is bound to session.");
              System.out.println(myBean);
              return mapping.findForward("success");
    }-------- show.jsp-----------
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
         <html:form action="/myUpdate">
              <table>
                   <tr>
                        <td>
                             <label><html:text property="name" name="info"/></label>
                        </td>
                   </tr>
                   <logic:iterate id="address" name="info" property="addressList" indexId="rowindex">
                        <tr>
                             <td>
                                  <html:text property="houseno" name="address" indexed="true"/>
                             </td>
                             <td>
                                  <html:text property="roadname" name="address" indexed="true"/>
                             </td>
                             <td>
                                  <html:text property="city" name="address" indexed="true"/>
                             </td>
                             <td>
                                  <html:text property="state" name="address" indexed="true"/>
                             </td>
                             <td>
                                  <html:text property="country" name="address" indexed="true"/>
                             </td>
                        </tr>
                   </logic:iterate>
                   <tr>
                        <html:submit title="Submit"/>
                   </tr>
              </table>
         </html:form>
    </body>
    </html>

  • How to send a String value  from Servlet to  Action class in Struts .

    when iam trying to send string value from Servlet to Struts Action class through Http Session, iam getting null value, iam really in big confusion, help me.

    please elaborate clearly or put you code of both action and servlet here
    Are both of them in same web application

  • Values from JSP to Struts Action Class

    Dear All,
    Am working on a small struts project, i want to get values from JSP in the Action class, i tried with sending variables using request through URL, it works fine, any other way is there to send the values from JSP to action class. Am not having any input fields in the JSP.I have links.
    Thanks,
    vyrav.

    I have a dispatch action for that am calling the action like this viewfiles.do?parameter=edit, and i have to send a variable ID from the same page, so am doing like this through java script, viewfiles.do?parameter=edit&id=10. Am able to get the id in the dispatch action edit, but when i start tomcat with security manager its not calling the action itself and its giving accesscontrol exception, but when i directly type viewfiles.do in URL its calling the action.
    I dont know wats the problem, tomcat security manager not allowing this. Please help me.
    Thanks,
    vyrav.

  • How to retrieve values from the struts DAO to Struts JSP

    Hi friends,
    I have one question. i want to display values in the struts jsp file from the struts DAO class. can anyone tell how do it.
    Appreciated for your help.
    Thanks
    G1 :)

    Hi Santosh,
    Thanks for your prompt reply.
    Actually, my problem is i want to display complete rows from the DAO to JSP page. I'm displaying all the rows in the DAO from DB.
    But i dont know how to retrieve all these data from DAO. Can i take arraylist.??
    DAO:
    ------------     public Customers getData(Customers customers){ // Reading data from DB
         //ArrayList list = null ;
         try
              Connection conn = getSQLConnection();
              Statement statement = conn.createStatement();
              String qry = "select * from register";
              ResultSet resultSet = null;
              PreparedStatement pstat = conn.prepareStatement(qry);
              // pstat.setString(1, customers.getFname());
              resultSet = pstat.executeQuery();
    //Print the data to the console
    while(resultSet.next()){
              String fnam = resultSet.getString(1);
              String lnam = resultSet.getString(2);
              String gen = resultSet.getString(3);
              String addres = resultSet.getString(4);
              String cit = resultSet.getString(5);
              String zip = resultSet.getString(6);
              String county = resultSet.getString(7);
              String emal = resultSet.getString(8);
              System.out.println("First name:"+fnam);
              System.out.println("Last name:"+lnam);
              System.out.println("Address:"+addres);
              customers.setFname(fnam);
              customers.setLname(lnam);
              customers.setGender(gen);
              customers.setAddress(addres);
              customers.setCity(cit);
              customers.setZipcode(zip);
              customers.setCountry(county);
              customers.setEmail(emal);
                   statement.close();
                   conn.close();
              }catch(Exception e1){
                   e1.printStackTrace();
              return customers;
    Bean:
    I have specified in this line in Bean:
    request.getSession().setAttribute("customers", customers);
    But in JSP. how will i populate all these data. Pls..send some code.
    I'm sorry this is just practicals. i'm not doin any real time project. that;s why i have placed all these code.
    Thanks for your patience for resolving my problems.
    Thanks
    G1

  • How to call a method of an Action class from JSP on load?

    Hi guys
    Due to bad design pattern, i am forced to do something which i have not tried before.
    I need to call a method of a struts action class which invalidated the user session FROM the JSP itself on load. Which means it would not require user input.
    We have a subclass of a DispatchAction that handles all the incoming .dos.
    So http://blarblarblar:7001/blar/blar/doSomething.do?method=logout will dispatch to an Action class called DoSomething, into a method called logout().
    So when the webapp throws an exception, the ActionMapping actually displays an error.jsp and i have to invalidate the user at this stage.
    I can't change the most top level code in the base action class so i got to do it this way.
    Any help is much appreciated.
    Thanks.

    hi :-) DispatchAction is quite cool ;-)
    dont get much of your question but hope
    the suggestion below could help.
    A. use redirect?
    or
    B. autosubmit the form
    1. create your form in a jsp
       <html:form action="/doSomething" />
         <html:hidden name="method" value="logout" />
       </html:form>2. auto submit the form with method = logout
    put the function autosubmit in the "onLoad" event of the body
       <script>
         function autosubmit(){
         var form = document.yourformname;
         form.submit();
       <script>regards,

  • Can we call the pure java variable into the struts action class?

    Hi Everybody,
    I have created the binary tree data structure in java,Could I use the value of the variable called value in the struts action class?,pls help me thro ur reply.I have attached the java code here.Thanks in Advance
    package com.recipes.wizard.common;
    public class BinaryTreeTest {
      public static void main(String[] args) {
        new BinaryTreeTest().run();
      static class Node {
        Node left;
        Node right;
        int value;
        public Node(int value) {
          this.value = value;
      public void run() {
        Node root = new Node(5);
        System.out.println("Binary Tree Example");
        System.out.println("Building tree with root value " + root.value);
        insert(root, 1);
        insert(root, 8);
        insert(root, 6);
        insert(root, 3);
        insert(root, 9);
      public void insert(Node node, int value) {
        if (value < node.value) {
          if (node.left != null) {
            insert(node.left, value);
          } else {
            System.out.println("  Inserted " + *value* + " to left of "
                + node.value);
            node.left = new Node(value);
        else if (value > node.value) {
          if (node.right != null) {
            insert(node.right, value);
          } else {
            System.out.println("  Inserted " + *value* + " to right of "
                + node.value);
            node.right = new Node(value);
          if(node.value==1)
               System.out.println("The value is one");
             int output=node.value;
               System.out.println(output);
    }

    Hi,
    You can change the filter with the new cost element variable,Or you can assign the value of the new variable(if of same type)to old cost element ,but for that assignment again u have to change  planning function which you don't want.
    Regards,
    Indu

  • How to log off from SNC portal

    This is a very basic question. I did not find any button or menu option to log off. Sometimes I get the message that the transaction is still running in another session, and I find it very difficult to log off. I normally close the browser and then log off from the SCM system. But if I am not logged onto SAP and I open the portal directly, How do I log off?
    Your help is appreciated.
    Thanks
    Soumen

    Hi Soumen,
    There is no logoff button in SNC Web portal.
    You can close the SNC web protal to logoff.
    About your issue when you logoff it will locks your query as it is not logoff straight a way solution is create another query so that you can use another query or go to transaction SM04 and logoff your user-
    Regards,
    Nikhil

  • Returning xml from a struts action to be used by a ajax client

    Hello,
    I'm having issues with my ajax call on a WAS server. It functions correctly when run locally on tomcat and WSAD servers.
    It looks like the response isnt comming back when the ajax call is made.
    My java struts action does the following:
            String xml = .....
            aResponse.setContentType("text/xml");            
            aResponse.getWriter().write(xml);
            aResponse.getWriter().flush();
           return null;Is this the correct way to pass back a response?
    do I have to set the header? if so, what should it be?
    Thanks,
    Con.

    A JSP is usually easier to construct the XML since you have looping etc. - otherwise OK.

  • How to throws exception from subprocess?

    Hi,
    I use subprocess in my process and I need throws exception from subprocess to my main process.
    Thanks for help.
    Jakub

    The only to throw an exception from a sub process is by leveraging the Exception event (from the event view).
    You need to throw the exception, by dragging the Exception event and choose Throw into your subprocess. Then you need to add an exception "catcher" in the parent process to catch the Exception.
    Jasmin

  • Hello .. how to log out from apple device wothout pc or pc with video steps

    i want to log out from all Apple id on all apple device

    Hello there sarmad yasin,
    It sounds like you are looking for a way to sign out of all your Apple devices in one go. While this is not a function currently avaiable, you can reset your Apple ID password to prevent access to your information:
    Apple ID: Changing your password - Apple Support
    Follow these steps to change your Apple ID password. If you can't remember your password, follow the steps for what to do if you forget your Apple ID password.
    Go to My Apple ID (appleid.apple.com).
    Click “Manage your Apple ID” and sign in.
    If you have two-step verification turned on, you'll be asked to send a verification code to the trusted device associated with your Apple ID. If you're unable to receive messages at your trusted device, follow the guidelines for what to do if you can't sign in with two-step verification.
    Click "Password and Security".
    In the "Choose a new password" section, click Change Password. 
    Enter your old password, then enter a new password and confirm the new password. Click Save when done.
    The next time you use an Apple feature or service that uses Apple ID, you'll be asked to sign in with your new Apple ID password.
    Thank you for using Apple Support Communities.
    Cheers,
    Sterling

  • Runtime Exception from WDP generated interface class

    Hi,
    I am having runtime class cast exceptions from the Internal component file. There is no errors in compiling/building. The application is trying to use another method in the component in another DC. I believe some generated files may have go corrupt but i am not sure how to fix this. Anyone have any suggests? Or maybe other ideas what might be causing this.
    java.lang.ClassCastException
    at com.xxx.yyy.component.wdp.InternalABCComp.wdGetTestInterface(InternalABCComp.java:694)

    Hi,
        If this DC is using is using other components then the problem may be with the UsedDCs. Check if any one of them or their models are changed. Then you have to reimport the models in that DCs. (Hint: Build and deploy those DCs if there have problems you can find)
    REgards,
    Siva

  • Using static Delegates within Struts' Action classes

    HI,
    I have a struts app. I also have several delegate classes that connect to ejbs (session beans) used within my action classes. I was thinking about putting the delegates into a helper class as static properties. That way my action classes can just reference the same delegate. I don't want to have to create a new instance of a delegate with every request an action class handles.
    However, I'm wondering if this will cause synchronization issues with multiple requests being handle, as our site handles a heavy load of requests. Any suggestions would be appreciated?

    static will work - but IMO here's a better option
    1. Have multiple delegates (one per module - one for login, another for business process1, another for business process2)
    Advantages : Cleaner segregation, easier maintenance and readability.
    2. Maintain the business delegates as individual classes and access them through instance variables from action.
    Advantages : All the advantages of inheritance, one business process may be the child of another - for example you can have a BasePaymentDelegate and then a specific CreditCardPaymentDelegate extending it. Similarly a PaypalDelegate may also extend BasePaymentDelegate and then common functionality can be moved to the Base class.
    3. Cache the delegate instance variables in your action - so you dont have to create one per invocation. Having said that, all the business delegate methods should be stateless - all the data to a business method should be passed as local params.
    Advantages : Local variables are thread safe as long as the object itself are thread safe. So no synchronization issues.
    Hope that helps some
    Ram.

  • Exception not throwing to action class in Unix environment

    Hi
    We are using Weblogic Server 9.2.3.0.
    One of our EJB is not throwing exception to calling Action class in Unix environment. Its working fine in Windows.
    Somehow the EJB is swallowing the exception.
    any idea? I suspect it may be environmental issue?
    thank you

    Thanx for your reply.. I just found a solution and would like to share that with you. There are some default request parameters passed by the portal to the action class. "strutsAction" is one of them. If you print this parameters, you will see that it contains the complete url of your action. Now you can use String manipulation to extract the value of the parameters.
    I know its a crude solution. But it works fine.
    Best regards,
    Omer

  • How to create a savepoint in "BC4J transaction" from a struts Action

    Hello,
    I need to create a kind of savepoint in a transaction object in BC4J
    [    BC4JContext context = BC4JContext.getContext(request);
    context.getApplicationModule().getTransaction()."savepoint()" ]
    but it seems to me that it doesn't exist!!
    How can I do this.
    Thanks for help
    Mehdi

    Mehdi:
    BC4J does not support creation of savepoints in its transaction object. Savepoint support is quite tricky in that if we were to support it... If the transaction is rolled back to the SP, we would have to sync the cache back to the state when the SP was taken. And, this can be quite an expensive operation.
    Thanks.
    Sung

Maybe you are looking for

  • Trigger workflow for MIRO invoice creation

    Hello, In standard functionning it is not possible to trigger the workflow for documents coming from MM. When using transaction MIRO and selecting invoice creation the created document has following value : BKPF-AWTYP = 'RMRP'. whereas creating it fr

  • Java error in session initializations - IC web client

    Hi All, When i access the CRM IC web client through browser (BSP page), Page is loading but inside the page im getting the following error. " Java error in session initialization [Error message: abcj2systemid.domain.com: CALL_METHOD(SYS_METHODNAME) s

  • Star Trek Event Failure, At Least I Have Best Buy...

    I had tickets for the Maple Grove, MN Fathom Event: "Star Trek 25th Anniversary Celebration" today. It did not go well.  Tonight's event was not acceptable in any form: They kept the lights on 20 minutes into the start The audio was not synced up. Th

  • Upgraded to Lion and now my Admin account (the only account on the computer) is "Managed"

    I cannot change my password or share files, as it gives me an error about being allowed to. I am not using an LDAP account and this account was NOT managed before the upgrade. When I uncheck the "Enable Parental Controls" box, it gives me a message s

  • Trying to Improve a Very Slow UPDATE

    I am attempting to run an update that involves the following two tables. The indexes are listed below the table names, followed by the current number of records in the tables. The query contains come comments about results returned from the estimated