[转载]关于struts的学习!
来源:互联网 发布:依云订水软件 编辑:程序博客网 时间:2024/04/30 09:52
主要就是FormBean,Action还有ActionMapping的Forward搞清楚就是了 ,
在struts-cofig.xml文件中配置FormBean和Action:
<form-beans>
<form-bean name="book" type="com.xujun.BookForm">
//如果想添加formBean中没有的属性,可以这样自定义一个属性
<form-property name="srvName" type="java.lang.String"/>
</form-bean>
</form-beans>
<action-mappings>
//name 是指formbean的Name,path必须和jsp中的form的提交的action的path一样,type是
Action对应的class
<action name="book" path="/action" type="com.xujun.ShowBookAction"
validate="true">
<forward name="returnIndex" path="/index.jsp"/>
</action>
</action-mappings>
jsp页面:
<%@page contentType="text/html; charset=gb2312"%>
<%@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"%>
<html:html>
<body>
<html:form action="/action" method="POST">
<a>作者</a>
<html:text property="author" name="book"/>
<a>价格</a>
<!--<html:text property="price" name="book"/>-->
<html:select property="price" name="book">
<html:option value="100"> </html:option>
<html:option value="200"> </html:option>
</html:select>
<a>书名</a>
<html:text property="bookName" name="book"/>
<input type="reset" value="重 填">
<input type="submit" value="提 交">
<input type="button" value="返 回" onClick="javascript:history.back();">
</html:form>
</body>
</html:html>
Aciont:
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
public class ShowBookAction extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest servletRequest,
HttpServletResponse servletResponse) {
BookForm bookForm = (BookForm) actionForm;
double price = bookForm.getPrice();
System.out.println("" + price + " " + bookForm.getAuthor() + " " +
bookForm.getBookName());
return actionMapping.findForward("returnIndex");
}
}
FormBean可以用jbulider中的FormBean自动完成,struts-config可以用IDE的可视环境编辑。
用jbulider开发struts,非常方便和简单,jbuilder作的真是强大啊
- [转载]关于struts的学习!
- 关于struts中使用Tiles的初级步骤【非转载】
- 关于学习 Flex 的一点建议(转载)
- 【转载】关于模拟电路的学习历程
- 关于计算机图形学的学习(转载)
- 关于C++的学习(转载)
- 关于学习linux的建议(转载)
- Struts下的MapForm [转载]
- 发现了一个关于struts学习的不错网址
- 关于学习编程(struts)的一点小感想
- Struts 2 学习笔记:HelloWorld(转载)
- 【转载】struts 学习总结----开发流程
- 【转载】struts2 学习总结 ---- Struts-tags
- 【转载】Struts2学习总结----struts.xml 配置
- 【转载】struts 学习总结----开发流程
- 转载:) 关于spring、hibernate、struts的一些错误问题 不断补充中(靠自己了)
- 关于Struts的问题
- 关于Struts的select
- Oct 20th,2005 I need to study hard
- 文学常识连载三
- 转载--SQL Server 索引结构及其使用
- 疯狂填字600期游戏打包版发布
- java文件操作大全(转贴)
- [转载]关于struts的学习!
- copy the content of a file to another file.
- [转贴]弹出窗口详解
- 今天才申请的blog.我的网址是:http://www.wbzh.tk,http://blog.csdn.net/WBZH/
- Smarty的分页实现
- 正则表达式
- 表格动态调整(转)
- 什么叫做火星帖
- Winform下datagrid数据倒入excel