找到strtus
中的這個文件(struts
example
war)將它解包
(要用到裡面的很多文件)
在jb下安裝struts
(jb
裡的配置方法
可以參考一下)
Struts
比Struts
功能增強了很多
比如
提供DynaActionForms
可不用編寫任何代碼創建動態的ActionForm
多應用支持允許定義多個struts
config
xml配置文件等等
但JBuilder
只直接支持Struts
不直接支持Struts
下面讓我們來看看怎樣讓JBuilder
支持Struts
首先下載 jakarta
struts
把整個目錄放到/extras目錄下
接著在JBuilder用 Configure Libraries對話框 (Tools
>Configure Libraries)創建一個新的library
我們命名為Struts
把jakarta
struts
lib目錄下所有的jar添加到新的library裡
在library Settings裡設置Framework為Struts
點OK
設置完成
接下來看看設置是否成功
File
>New創建一個web application
在Web Application wizard的JSP/Servlet frameworks中我們看到了Struts
選擇框
設置成功!
接下來您就可以在JBuilder
裡使用Struts
開發您的Web Application了
配置struts
config
xml文件 (文件如下:)
<?xml version=
encoding=
UTF
?>
<!DOCTYPE struts
config PUBLIC
//Apache Software Foundation//DTD Struts Configuration
//EN
config_
_
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>
建立 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;
}
}
建立 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=
javascript
src=
staticjavascript
jsp
></script>
</body>
</html:html>
建立 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
);
}
}
Copy 文件:
validation
xml
validation
rule
xml
ApplicationResources
properties
staticjavascript
jsp
編緝validate
xml文件(不完整
只要一個Form)
<form name=
testForm
>
<field property=
testText
depends=
required
minlength
maxlength
>
<arg
key=
prompt
username
/>
<arg
key=
${var:minlength}
name=
minlength
resource=
false
/>
<arg
key=
${var:maxlength}
name=
maxlength
resource=
false
/>
<var>
<var
name>maxlength</var
name>
<var
value>
</var
value>
</var>
<var>
<var
name>minlength</var
name>
<var
value>
</var
value>
</var>
</field>
</form>
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28532.html