1.找到strtus1.1 中的这个文件(struts-example.war)将它解包。(要用到里面的很多文件)
2.在jb下安装struts1.1(jb9里的配置方法,可以参考一下)
struts1.1比struts1.0功能增强了很多。比如:提供dynaactionforms,可不用编写任何代码创建动态的actionform;多应用支持允许定义多个struts-config.xml配置文件等等。但jbuilder 9只直接支持struts1.0,不直接支持struts1.1,下面让我们来看看怎样让jbuilder 9支持struts1.1。
首先下载 jakarta-struts-1.1,把整个目录放到/extras目录下.
接着在jbuilder用 configure libraries对话框 (tools-->configure libraries)创建一个新的library ,我们命名为struts1.1,把jakarta-struts-1.1lib目录下所有的jar添加到新的library里,在library settings里设置framework为struts,点ok,设置完成.
接下来看看设置是否成功:
file-->new创建一个web application, 在web application wizard的jsp/servlet frameworks中我们看到了struts 1.1选择框,设置成功!
接下来您就可以在jbuilder9里使用struts1.1开发您的web application了.
3.配置struts-config.xml文件 (文件如下:)
<?xml version="1.0" encoding="utf-8"?>
<!doctype struts-config public "-//apache software foundation//dtd struts configuration 1.1//en" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd";>
<struts-config>
<form-beans>
<form-bean name="testform" type="test.testform" />
</form-beans>
<action-mappings>
<action name="testform" type="test.testaction" validate="true" scope="request" path="/testaction">
<forward name="test" path="/test.jsp" />
</action>
</action-mappings>
<message-resources parameter="test.applicationresources" />
<plug-in classname="org.apache.struts.validator.validatorplugin">
<set-property value="/web-inf/validator-rules.xml,/web-inf/validation.xml" property="pathnames" />
</plug-in>
</struts-config>
3.建立 testform.java 继承validateform
package test;
import org.apache.struts.validator.*;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class testform extends validatorform {
private string testtext;
public void settesttext(string testtext) { this.testtext = testtext; }
public string gettesttext() { return testtext; }
public actionerrors validate(actionmapping actionmapping, httpservletrequest httpservletrequest) { return null; }
public void reset(actionmapping actionmapping, httpservletrequest httpservletrequest) {
testtext = null;
}
}
4.建立 test.jsp
<%@ page contenttype="text/html; charset=gbk" %>
<%@ taglib uri="/web-inf/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/web-inf/struts-html.tld" prefix="html" %>
<%@ taglib uri="/web-inf/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/web-inf/struts-template.tld" 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="javascript1.1" src="staticjavascript.jsp"></script>
</body>
</html:html>
5.建立 testaction.java
package test;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class testaction extends action {
public actionforward perform(actionmapping mapping, actionform actionform, httpservletrequest httpservletrequest, httpservletresponse httpservletresponse) {
return mapping.findforward("test");
}
}
6.copy 文件:
validation.xml,
validation-rule.xml,
applicationresources.properties,
staticjavascript.jsp
7.编缉validate.xml文件(不完整,只要一个form)
<form name="testform">
<field property="testtext"
depends="required, minlength,maxlength">
<arg0 key="prompt.username"/>
<arg1 key="${var:minlength}" name="minlength"
resource="false"/>
<arg2 key="${var:maxlength}" name="maxlength"
resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>16</var-value>
</var>
<var>
<var-name>minlength</var-name>
<var-value>3</var-value>
</var>
</field>
</form>
闽公网安备 35060202000074号