找到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>