• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts DispatchAction "Wierd Parameter Error"

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting the "parameter 'mode' not found error" in struts DispatchAction when the user session gets expired. The code works perfectly when the session is not expired. But when the session gets expired suddenly Struts says it is not able to find parameter "mode" for action and throws error.

The Action class code is as follows. Take a look at the add(...) method.


code:
--------------------------------------------------------------------------------

package com.xxx.lms.actions; import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action;import org.apache.struts.action.ActionError;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionMessage;import org.apache.struts.action.ActionMessages;import org.apache.struts.actions.DispatchAction; import com.xxx.lms.dao.*;import com.xxx.lms.vo.*;import com.xxx.lms.forms.AddBookForm;import com.xxx.lms.vo.MasterData;import com.xxx.lms.vo.User; import org.apache.commons.beanutils.BeanUtils; import java.sql.SQLException;import java.util.*;import javax.servlet.http.*; public class BookAction extends DispatchAction { public ActionForward show(ActionMapping mapping, ActionForm form, HttpServletRequest hreq, HttpServletResponse hres){ActionForward forward = new ActionForward();ActionErrors errors = new ActionErrors();BookDAO dao = null;System.out.println("Inside BookAction: Show");try{dao = new BookDAO();MasterData results = dao.queryDataForListBox();if(results != null){HttpSession sess = hreq.getSession(false);sess.setAttribute("master_data",results);}elseSystem.out.println("BookAction: Results is Empty");forward = mapping.findForward("show_success");}catch(SQLException e){errors.add("Database Error",new ActionError("error.database"));System.out.println("BookAction: Database Error");forward = mapping.findForward("failure");}catch(Exception e){errors.add("Unexpected Error",new ActionError("error.unexpected"));System.out.println("BookAction: Unexpected Error");forward = mapping.findForward("failure");}saveErrors(hreq,errors); // save the error objects for displaySystem.out.println("Leaving BookAction");return forward; }public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest hreq, HttpServletResponse hres){ActionForward forward = new ActionForward();ActionErrors errors = new ActionErrors();ActionMessages msgs = new ActionMessages();BookDAO dao = null;System.out.println("Inside BookAction: Add");try{dao = new BookDAO();AddBookForm abform = (AddBookForm) form; int user_id = -1;HttpSession sess = hreq.getSession(false);if(sess != null && sess.getAttribute("user")!= null){User user = (User)sess.getAttribute("user");if(user.getAdmin_status().equalsIgnoreCase("y")){user_id = user.getUser_id();if(dao.searchBooksForDuplicate(abform.getBook_name()) > 0) // duplicate found{errors.add("book.add.failure", new ActionError("book.add.duplicate"));forward = mapping.findForward("failure");}else{AddBookVO bookvo = new AddBookVO();BeanUtils.copyProperties(bookvo,abform);int status = dao.addBook(bookvo,user_id);System.out.println(status);if(status > 0){msgs.add("book.add.status", new ActionMessage("book.add.success"));msgs.add("book.add.status", new ActionMessage("book.add.success.newid",""+status+""));}elsemsgs.add("book.add.status", new ActionMessage("book.add.failed"));forward = mapping.findForward("add_success");}}else{System.out.println("Insufficient Privileges for User");errors.add("book.add.failure", new ActionError("insufficient.privileges"));forward = mapping.findForward("failure");}}else{System.out.println("Session Expired");msgs.add("book.add.failure", new ActionMessage("session.expired"));forward = mapping.findForward("session_expired");}}catch(Exception e){e.printStackTrace();errors.add("book.add.failure",new ActionError("error.unexpected"));System.out.println("BookAction: Unexpected Error");forward = mapping.findForward("failure");}saveErrors(hreq,errors); // save the error objects for displaysaveMessages(hreq,msgs);System.out.println("Leaving BookAction: Add");return forward; }}

--------------------------------------------------------------------------------




struts-config.xml
*****************

code:
--------------------------------------------------------------------------------

<action path="/addBook" type="com.xxx.lms.actions.BookAction" parameter="mode" name="addBookForm" scope="request"><forward name="show_success" path="/jsp/AddBook.jsp"></forward><forward name="failure" path="/jsp/AddBook.jsp"></forward><forward name="add_success" path="/jsp/AddBook.jsp"></forward><forward name="session_expired" path="/Login.jsp"></forward></action>

--------------------------------------------------------------------------------



I use hidden fields in the JSP page front-end to pass the parameter 'mode' to the BookAction class.

When the session gets expired, i get all the log (System.out) messages in the BookAction class which says "Session Expired", but after the forward happens (to 'session_expired'), Struts throws the parameter 'mode' not found error. As the ActionForward has already happened to 'session_expired', and the execute() method returns successfully, i'm not sure why some DispatchAction again comes to picture here. The request should have been passed to the 'Login.jsp' page and not into some DispatchAction.

I'm not sure why this kind of error occurs.

Please do let me know if some other info is needed from my side.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
If you have an Action class which extends DispatchAction class the mapping for it in the struts config will be as follows
<action path="/logon"
type="com.actions.LogonAction"
name="logonForm"
input="/pages/standard/logon.jsp" parameter="option">
//forwards
</action>
For example the above mapped action class is having three methods, login, insert and delete.
Now in your jsp when you want to call login you will give
<forms:action name="/logon?option=login">
Same way you need to call insert by giving option=insert or delete. So automactically you button click will be redirected to respective methods.
This will be called on the button clicks.
I hope this will help you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic