how to write struts-config.xml if no action and form?

2004-08-23 Thread Ping Cheung Leung
If a form is to be called with DispatchAction, then I have
to pass <.. parameter="method" ..> in struts-config.xml.
If the form is called from a JSP file and it does not have
an entry in struts-config.xml, what can I do?
 
Should I an entry for the JSP file in struts-config.xml?
 


-
聊天室、收音機、Games 等多項功能
全新 Yahoo! Messenger
http://messenger.yahoo.com.hk

Re: How to avoid duplicated submission by token?

2004-08-22 Thread Ping Cheung Leung
Thanks Rick.
Let me find out what DispatchAction is and then come
back.


 --- Rick Reumann <[EMAIL PROTECTED]> 內容:
> HI, Ping, you have so many different things going on
> in one action
> execute method that it is very difficult to follow
> everything. Also, you
> are doing a lot of things that do not need to be
> done (usually) from
> your action such as calling form.reset(), removing
> form bean, removing
> mappings, etc. You are doing way too many different
> things in one Action
>  ... you either need to A) Use a DispatchAction or
> B) create different
> Action classes to perform the different tasks.
> 
> Once you do that, the first action dispatch method
> you go to before
> hitting your form you do
> 
> saveToken(request);
> 
> Then in the action method that you want to make sure
> duplicate submits
> don't occur you do your check...:
> 
> isTokenValid(request))
> 
> Then when I leave that method (if it was valid
> token) I do...
> 
> resetToken(request);
> saveToken(request);
> 
> 
> So, if I were you, I'd simply create a
> DispatchAction with the methods...
> 
> 
> setUp(.. )
> 
> updateUserProfile(.. )
> 
> cancel(... )
> 
> 
> 
> 
> 
> Ping Cheung Leung wrote:
> 
> > My attention is to prevent duplicated submission.
> > I have refered to the struts-example.
> > It checks the valid of token by IsValidToken().
> > However when a form is displayed at the first
> time,
> > it always is invalid.
> > 
> > Moreover, according to the struts-example, it
> > saveToken when it finds error.
> > 
> > The behavior becomes very strange.
> > 
> > When a form is displayed at the first time, it is
> > invalid. It leads to error message displaying on
> web
> > page. Next time user clicks the submit button, it
> > becomes valid. Then it cannot avoid duplicated
> > submission.
> > 
> > All I want is very simple. When user clicks a
> submit
> > button. It saves record if data checking is ok.
> > If user goes back and re-click the submit button.
> > Duplicated submission should be detected.
> > 
> > Below is my codings. What needs to be changed
> > so that duplicated submission can be avoided?
> > 
> > package com.erp.quotation;
> > 
> > import java.util.Locale;
> > import org.apache.struts.action.*;
> > import javax.servlet.http.*;
> > import org.apache.commons.logging.Log;
> > import org.apache.commons.logging.LogFactory;
> > import org.apache.struts.util.MessageResources;
> > 
> > public final class AddUserProfileAction extends
> Action
> > {
> > 
> >  private Log log =
> >
>
LogFactory.getFactory().getInstance(this.getClass().getName());
> >  
> >  
> >  public ActionForward execute (ActionMapping
> mapping,
> >ActionForm form,
> >HttpServletRequest request,
> >HttpServletResponse response) 
> >throws Exception {
> > 
> >if (isCancelled(request)) {
> >  if (log.isInfoEnabled()) {
> > log.info(" " + mapping.getAttribute()
> + "
> > - Registration transaction was cancelled");
> >  }
> >  removeFormBean(mapping, request);
> >  return mapping.findForward("cancel");
> >}
> >
> >HttpSession session = request.getSession();
> >ActionErrors errors = new ActionErrors();
> >   if (log.isTraceEnabled()) {
> >   log.trace(" Checking transactional
> control
> > token");
> >   }   
> >   if (!isTokenValid(request)) {
> >  log.trace("valid token");
> >   errors.add(ActionErrors.GLOBAL_ERROR,
> >  new
> > ActionError("error.transaction.token"));
> >   } else {
> >log.trace("invalid token");
> >   }
> >   resetToken(request);   
> >   
> >  Locale locale = getLocale(request);
> >  MessageResources messages =
> > getResources(request);
> >  String action =
> request.getParameter("action");
> > 
> >  if (checking_is_ok) {
> >  save_record_to_database();
> >  ActionMessages actionMessages = new
> > ActionMessages();
> >  ActionMessage actionMessage = new
> > ActionMessage("statusLine.recordAdded");
> >  actionMessages.add(Consta

How to avoid duplicated submission by token?

2004-08-22 Thread Ping Cheung Leung
My attention is to prevent duplicated submission.
I have refered to the struts-example.
It checks the valid of token by IsValidToken().
However when a form is displayed at the first time,
it always is invalid.

Moreover, according to the struts-example, it
saveToken when it finds error.

The behavior becomes very strange.

When a form is displayed at the first time, it is
invalid. It leads to error message displaying on web
page. Next time user clicks the submit button, it
becomes valid. Then it cannot avoid duplicated
submission.

All I want is very simple. When user clicks a submit
button. It saves record if data checking is ok.
If user goes back and re-click the submit button.
Duplicated submission should be detected.

Below is my codings. What needs to be changed
so that duplicated submission can be avoided?

package com.erp.quotation;

import java.util.Locale;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.util.MessageResources;

public final class AddUserProfileAction extends Action
{

 private Log log =
LogFactory.getFactory().getInstance(this.getClass().getName());
 
 
 public ActionForward execute (ActionMapping mapping,
   ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response) 
   throws Exception {

   if (isCancelled(request)) {
 if (log.isInfoEnabled()) {
log.info(" " + mapping.getAttribute() + "
- Registration transaction was cancelled");
 }
 removeFormBean(mapping, request);
 return mapping.findForward("cancel");
   }
   
   HttpSession session = request.getSession();
   ActionErrors errors = new ActionErrors();
  if (log.isTraceEnabled()) {
  log.trace(" Checking transactional control
token");
  }   
  if (!isTokenValid(request)) {
 log.trace("valid token");
  errors.add(ActionErrors.GLOBAL_ERROR,
 new
ActionError("error.transaction.token"));
  } else {
   log.trace("invalid token");
  }
  resetToken(request);   
  
 Locale locale = getLocale(request);
 MessageResources messages =
getResources(request);
 String action = request.getParameter("action");

 if (checking_is_ok) {
 save_record_to_database();
 ActionMessages actionMessages = new
ActionMessages();
 ActionMessage actionMessage = new
ActionMessage("statusLine.recordAdded");
 actionMessages.add(Constants.statusLine,
actionMessage);
 saveMessages (request, actionMessages);
 saveToken(request);
 addUserProfileForm.reset(mapping, request);
 return mapping.findForward("success");  
 }
 // Remove the obsolete form bean
 if (mapping.getAttribute() != null) {
if ("request".equals(mapping.getScope()))
  
request.removeAttribute(mapping.getAttribute());
else
  
session.removeAttribute(mapping.getAttribute());
 } 
 if (!errors.isEmpty()) {
saveErrors(request, errors);
saveToken(request);
return (mapping.getInputForward());
 }
   return mapping.findForward("failure");   
 } 

}

_
必殺技、飲歌、小星星...
浪漫鈴聲  情心連繫
http://us.rd.yahoo.com/evt=22281/*http://ringtone.yahoo.com.hk/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Can I generate a token without Action class?

2004-08-21 Thread Ping Cheung Leung
My attention is to prevention duplicated submission.
I have refered to the struts-example.
It checks the valid of token by IsValidToken().
However when a form is displayed at the first time,
it always is invalid.

Moreover, according to the struts-example, it
saveToken when it finds error.

The behavior becomes very strange.

When a form is displayed at the first time, it is
invalid. It leads to error message displaying on web
page. Next time user clicks the submit button, it
becomes valid. Then it cannot avoid duplicated
submission.

All I want is very simple. When user clicks a submit
button. It saves record if data checking is ok.
If user goes back and re-click the submit button.
Duplicated submission can be detected.

Any coding example can be provided?
Or can u point out my mistakes if I provide my
codings?


 --- Michael McGrady <[EMAIL PROTECTED]> 內容:
> Ping Cheung Leung wrote:
> 
> >I have a web page presented by JSP only.
> >No data to input. It contains several links only.
> >
> >If I click one of the links on the web page,
> >It will go to another web page with a form to input
> >data.
> >If I want the form to have a token generated 
> >when the form first appears.
> >How can I code it?
> >
> >The procedure saveToken() is inside an Action
> class.
> >However the JSP file does not have a
> >corresponding ValidatorForm class and Action class.
> >
> >How can a token be generated in a form when the
> form
> >first appears?
> >For instance, when the form is re-directed from a
> JSP
> >file or others?
> >  
> >
> 
> You need to do a little reading or a little research
> into the code on
> how these work. Essentially the idea is that a token
> is saved in request
> and in session scopes and the logic is determined by
> those two being
> compared against each other to allow us to determine
> whether or not a
> person should be able to access the Action class at
> all. So, you need to
> understand that the basic idea is saving, resetting,
> etc. tokens to
> compare against each other.
> 
> 
>
-
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
>  

_
必殺技、飲歌、小星星...
浪漫鈴聲  情心連繫
http://us.rd.yahoo.com/evt=22281/*http://ringtone.yahoo.com.hk/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Can I generate a token without Action class?

2004-08-21 Thread Ping Cheung Leung
I have a web page presented by JSP only.
No data to input. It contains several links only.

If I click one of the links on the web page,
It will go to another web page with a form to input
data.
If I want the form to have a token generated 
when the form first appears.
How can I code it?

The procedure saveToken() is inside an Action class.
However the JSP file does not have a
corresponding ValidatorForm class and Action class.

How can a token be generated in a form when the form
first appears?
For instance, when the form is re-directed from a JSP
file or others?


_
必殺技、飲歌、小星星...
浪漫鈴聲  情心連繫
http://us.rd.yahoo.com/evt=22281/*http://ringtone.yahoo.com.hk/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



what does resetToken() do?

2004-08-21 Thread Ping Cheung Leung
I find no difference if I saveToken() without
resetToken() first.
Does it reset token to zeroes?
What does resetToken do?



_
必殺技、飲歌、小星星...
浪漫鈴聲  情心連繫
http://us.rd.yahoo.com/evt=22281/*http://ringtone.yahoo.com.hk/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]