您的位置:首页 > 编程语言 > Java开发

struts 及使用标签的一些步骤

2008-11-15 12:43 281 查看
1配置struts
copy lib web.xml struts-config.xml
配制Action (注意path=/login 有/无.do 但是在其他jsp向转发则需写login.do 不是/login.do)
<action path="/login" type="login.LoginAction" name="loginForm"
scope="request">
<forward name="success" path="/loginSuccess.jsp"></forward>
<forward name="error" path="/loginError.jsp"></forward>
</action>

struts标签配制

1 struts-config中加入
<message-resources parameter="ApplicationResources" />
2
复制ApplicationResources.properties 到src目录下
3

jsp 中加

<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>

/////////////logic 中的id 变量是把其存为一个变量,默认是page 范围内的变量

/////////////

<logic:notEmpty name="list">

<logic:iterate id="index" name="list">
用户名
<bean:write name="index" property="username" />
<br>年龄
<bean:write name="index" property="age" />
<br>所属组名:
<bean:write name="index" property="g.name" /><br><p><p>
</logic:iterate>

<bean:write name="index" />

</logic:notEmpty>

struts 文件上传的一些注意:

<form action="uploadAction.do" method ="post"enctype="multipart/form-data">
文件名:
<input type="text" name="filename"><br>
file: <input type="file" name="file"><br>

<input type="submit" value="submit"><br>
</form>

file: <input type="file" name="file"><br> 这一行的name="file" 的"file"中不能出现空格,file在struts Form类中必须具有同样的名字,且为org.apache.struts.upload.FormFile;类

method ="post"enctype="multipart/form-data" 要同时存在,不能只具其一

一些关于上传的配置可以在struts-config中配制,例如文件最大大小等:如下

<controller maxFileSize="10M" ></controller>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: