熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

struts1.1裡的頁面有效驗證

2022-06-13   來源: Java開源技術 

  找到strtus 中的這個文件(strutsexamplewar)將它解包(要用到裡面的很多文件)
  在jb下安裝struts(jb裡的配置方法可以參考一下)
  
  Struts比Struts功能增強了很多比如提供DynaActionForms可不用編寫任何代碼創建動態的ActionForm多應用支持允許定義多個strutsconfigxml配置文件等等但JBuilder 只直接支持Struts不直接支持Struts下面讓我們來看看怎樣讓JBuilder 支持Struts
  
  首先下載 jakartastruts把整個目錄放到/extras目錄下
  
  接著在JBuilder用 Configure Libraries對話框 (Tools>Configure Libraries)創建一個新的library 我們命名為Struts把jakartastrutslib目錄下所有的jar添加到新的library裡在library Settings裡設置Framework為Struts點OK設置完成
  
  接下來看看設置是否成功
  File>New創建一個web application 在Web Application wizard的JSP/Servlet frameworks中我們看到了Struts 選擇框設置成功!
  接下來您就可以在JBuilder裡使用Struts開發您的Web Application了
  
  
  配置strutsconfigxml文件 (文件如下:)
  
  <?xml version= encoding=UTF?>
  <!DOCTYPE strutsconfig PUBLIC //Apache Software Foundation//DTD Struts Configuration //EN config__dtd;>
  <strutsconfig>
  <formbeans>
  <formbean name=testForm type=testtestForm />
  </formbeans>
  <actionmappings>
  <action name=testForm type=testtestAction validate=true scope=request path=/testAction>
  <forward name=test path=/testjsp />
  </action>
  </actionmappings>
  <messageresources parameter=testApplicationResources />
  <plugin className=orgapachestrutsvalidatorValidatorPlugIn>
  <setproperty value=/WEBINF/validatorrulesxml/WEBINF/validationxml property=pathnames />
  </plugin>
  </strutsconfig>
  
  建立 testFormjava 繼承ValidateForm
  
  package test;
  
  import orgapachestrutsvalidator*;
  import orgapachestrutsaction*;
  import javaxservlethttp*;
  
  public class testForm extends ValidatorForm {
  private String testText;
  public void setTestText(String testText) { thistestText = testText; }
  public String getTestText() { return testText; }
  public ActionErrors validate(ActionMapping actionMapping HttpServletRequest httpServletRequest) { return null; }
  
  public void reset(ActionMapping actionMapping HttpServletRequest httpServletRequest) {
  testText = null;
  }
  }
  
  建立 testjsp
  
  <%@ page contentType=text/html; charset=GBK %>
  <%@ taglib uri=/WEBINF/strutsbeantld prefix=bean %>
  <%@ taglib uri=/WEBINF/strutshtmltld prefix=html %>
  <%@ taglib uri=/WEBINF/strutslogictld prefix=logic %>
  <%@ taglib uri=/WEBINF/strutstemplatetld prefix=template %>
  
  <html:html>
  <head> <title> test </title> </head>
  <body bgcolor=#ffffff>
  
  <html:form action=/testAction onsubmit=return validateTestForm(this);>
  testText <html:text property=testText/>
  </html:form>
  
  <html:javascript formName=testForm
  dynamicjavascript=true
  staticjavascript=false/>
  <script language=javascript src=staticjavascriptjsp></script>
  
  </body>
  </html:html>
  
  建立 testActionjava
  
  
  package test;
  
  import orgapachestrutsaction*;
  import javaxservlethttp*;
  
  public class testAction extends Action {
  public ActionForward perform(ActionMapping mapping ActionForm actionForm HttpServletRequest httpServletRequest HttpServletResponse httpServletResponse) {
  return mappingfindForward(test);
  }
  }
  
  Copy 文件:
  
  validationxml
  
  validationrulexml
  
  ApplicationResourcesproperties
  
  staticjavascriptjsp
  
  編緝validatexml文件(不完整只要一個Form)
  
  <form name=testForm>
  
  <field property=testText
  depends=required minlengthmaxlength>
  <arg key=promptusername/>
  <arg key=${var:minlength} name=minlength
  resource=false/>
  <arg key=${var:maxlength} name=maxlength
  resource=false/>
  <var>
  <varname>maxlength</varname>
  <varvalue></varvalue>
  </var>
  <var>
  <varname>minlength</varname>
  <varvalue></varvalue>
  </var>
  </field>
  </form>
  

From:http://tw.wingwit.com/Article/program/Java/ky/201311/28532.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.