首先必須要通過一個Action再轉向那個添加記錄的頁面,轉向函數如下.?public ActionForward tokenTest(???ActionMapping mapping,???ActionForm form,???HttpServletRequest request,???HttpServletResponse response) throws Exception {??saveToken(request);//把一個token ID保存到Session,并在且要轉到的頁面?????? //的<html:form>中添加一個<input type="hideen">的標答.??return mapping.findForward("add");?}一個輸出入頁面如容如下:<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="<%@ taglib uri="<%@ taglib uri="<%@ taglib uri=" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html:html lang="true">? <head>??? <html:base />??? ??? <title>tokentest.jsp</title>??? ??? <meta http-equiv="pragma" content="no-cache">??? <meta http-equiv="cache-control" content="no-cache">??? <meta http-equiv="expires" content="0">??? ??? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">??? <meta http-equiv="description" content="This is my page">? </head>? ? <body>????? <br>????? <logic:present name="error">???????? <pre style="color:#ff2255"><bean:write name="error"/></pre>????? </logic:present>????? <center>????? <html:form action="/insert.do" method="post">??????? <table border="0" cellspacing="0" >????????? <tr>??????????? <td width="30%">用戶名</td>??????????? <td width="70%"><html:text property="username"/></td>????????? </tr>????????? <tr>??????????? <td>地址:</td>??????????? <td><html:text property="address"/></td>????????? </tr>????????? <tr>??????????? <td colspan="2"><html:submit value="提交"/></td>????????? </tr>??????? </table>?????? </html:form>????? </center>? </body></html:html>頁面的處理Action內容如下:? ?public ActionForward execute(??ActionMapping mapping,??ActionForm form,??HttpServletRequest request,??HttpServletResponse response) {??TokenTestForm tokenTestForm = (TokenTestForm) form;??if(!isTokenValid(request)){ //重復提交???request.setAttribute("error","不能得復提交!!!");???//saveToken(request); 重新生成tokenid,???return mapping.findForward("return");??}else{???resetToken(request);??}??//執行相關操作??System.out.println(tokenTestForm.getUsername()+"--"+tokenTestForm.getAddress());??return mapping.findForward("ok");?}至此已完成,至于原理,就自己去查一些資料就完全明白了.... posted on 2006-04-09 15:21 有貓相伴的日子 閱讀(1982) 評論(3) 編輯 收藏
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html:html lang="true">? <head>??? <html:base />??? ??? <title>tokentest.jsp</title>??? ??? <meta http-equiv="pragma" content="no-cache">??? <meta http-equiv="cache-control" content="no-cache">??? <meta http-equiv="expires" content="0">??? ??? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">??? <meta http-equiv="description" content="This is my page">? </head>? ? <body>????? <br>????? <logic:present name="error">???????? <pre style="color:#ff2255"><bean:write name="error"/></pre>????? </logic:present>????? <center>????? <html:form action="/insert.do" method="post">??????? <table border="0" cellspacing="0" >????????? <tr>??????????? <td width="30%">用戶名</td>??????????? <td width="70%"><html:text property="username"/></td>????????? </tr>????????? <tr>??????????? <td>地址:</td>??????????? <td><html:text property="address"/></td>????????? </tr>????????? <tr>??????????? <td colspan="2"><html:submit value="提交"/></td>????????? </tr>??????? </table>?????? </html:form>????? </center>? </body></html:html>頁面的處理Action內容如下:? ?public ActionForward execute(??ActionMapping mapping,??ActionForm form,??HttpServletRequest request,??HttpServletResponse response) {??TokenTestForm tokenTestForm = (TokenTestForm) form;??if(!isTokenValid(request)){ //重復提交???request.setAttribute("error","不能得復提交!!!");???//saveToken(request); 重新生成tokenid,???return mapping.findForward("return");??}else{???resetToken(request);??}??//執行相關操作??System.out.println(tokenTestForm.getUsername()+"--"+tokenTestForm.getAddress());??return mapping.findForward("ok");?}至此已完成,至于原理,就自己去查一些資料就完全明白了....