jdonFramework4.0中如何避免重复提交

06-06-24 luo6327529
我在提交后刷新页面出现了重复提交的问题

请问板桥兄如何解决

banq
2006-06-25 21:42
本站以前有专门讨论,很多高人都提了建议,可查查。

luo6327529
2006-06-26 08:54
我这样写的

public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response)

throws Exception {

intContext(this.getServlet().getServletContext());

checkConfigName(actionMapping);

EventModel em = null;

String formName = FormBeanUtil.getFormName(actionMapping);

ModelHandler modelHandler = modelManager.borrowtHandlerObject(formName);

if (isTokenValid(request,true)) {

try {

ModelForm form = getModelForm(modelHandler, actionForm, request);

ModelForm theForm=(ModelForm) actionForm;

ModelIF model = makeModel(actionMapping, actionForm, request, modelHandler);

String encoding = request.getCharacterEncoding();

if ((encoding != null) && (encoding.equalsIgnoreCase("utf-8")))

{

response.setContentType("text/html; charset=gb2312");

}

List myFiles =theForm.getMyFiles();

UploadFile uploadFile = null;

for(int i =0;i<myFiles.size();i++){

UpFile upFile = (UpFile) myFiles.get(i);

FormFile file = upFile.getFile();

if (file != null) {

try {

InputStream stream = file.getInputStream();//把文件读入

String filePath = request.getRealPath("/");//取当前系统路径

ByteArrayOutputStream baos = new ByteArrayOutputStream();

String str="house";

OutputStream bos = new FileOutputStream(filePath + "/upfile/" +str+

upFile.getFilename());//建立一个上传文件的输出流

int bytesRead = 0;

byte[] buffer = new byte[8192];

while ( (bytesRead = stream.read(buffer, 0, 8192)) != -1) {

bos.write(buffer, 0, bytesRead);//将文件写入服务器

}

bos.close();

stream.close();

String path="";

path="\\upfile\\"+str+upFile.getFilename()+";";

form.setPicPath(path);

}catch(Exception e){

System.err.print(e);

}

//能运行到这里,就可以使用单个文件上传的方法进行上传了。循环而已

System.out.println("filename:::" + file.getFileName());

System.out.println("file size:::" + file.getFileSize()/1024+"KB");

}

}

modelHandler.formCopyToModelIF(form, model);

em = new EventModel();

em.setActionName(form.getAction());

em.setModelIF(model);

em.setActionType(FormBeanUtil.actionTransfer(form.getAction()));

Debug.logVerbose("[JdonFramework] save data to database ... ", module);

//deleagte the Modelhandler's serviceAction

modelHandler.serviceAction(em, request);

modelHandler.modelIFCopyToForm(em.getModelIF(), form);

} catch (Exception ex) {

Debug.logError("[JdonFramework]please check your service 、 model or form :" + ex, module);

throw new Exception("System error! please call system Admin." + ex);

} finally {

modelManager.returnHandlerObject(modelHandler);

}

if (em.getErrors() != null) {

Debug.logError("[JdonFramework] save error!! " + em.getErrors(), module);

ActionMessages errors = new ActionMessages();

ActionMessage error = new ActionMessage(em.getErrors());

errors.add(ActionMessages.GLOBAL_MESSAGE, error);

saveErrors(request, errors);

ActionForward af = actionMapping.findForward(FormBeanUtil.FORWARD_FAILURE_NAME);

if (af != null)

return af;

else

return actionMapping.findForward(FormBeanUtil.FORWARD_SUCCESS_NAME);

} else {

Debug.logVerbose("[JdonFramework] save successfully ... ", module);

return actionMapping.findForward(FormBeanUtil.FORWARD_SUCCESS_NAME);

}

}

else

{

saveToken(request);

}

return actionMapping.findForward(FormBeanUtil.FORWARD_SUCCESS_NAME);

}

不知为什么,在第一次提交时,不能成功

在新开一个页面提交确能成功(第二次提交)

不知道代码错在那里,请板桥兄给予指教

banq
2006-06-26 18:34
不太看得出来,感觉写文件这段有问题,会比较慢。

直接使用FileInputStream(大概)直接写就可以,不要用while循环,

另外写文件这段属于业务逻辑,应该在Service中实现,在Action中就直接将ActionForm和Model做个转换,然后将UploadFile传到Service中即可。

可参见21日更新得JiveJdon3源码。

banq
2006-06-30 15:22
为防止并发点击Clickstream,特点:

1.在用户Session开始跟踪点击。

2.跟踪每次用户点按的信息(via a Servlet Filter).

3.当用户Session退出后,将点按信息记录到一个文件中

http://www.opensymphony.com/clickstream/

在web.xml中配置:

 <filter>
        <filter-name>rewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
        <init-param>
            <param-name>logLevel</param-name>
            <param-value>commons</param-value>
        </init-param>
    </filter>
<p>

猜你喜欢