struts 的基本练习
来源:互联网 发布:软件是无形资产 编辑:程序博客网 时间:2024/05/17 05:03
看struts2的时候,方法一是抄书,方法二maven,方法三乱来。
1、struts2就和。net的基本library一样首先是全部引用,必要的库有个列表,类似angel,struts2-core、asm-tree3个asm,common下面的3个,work-core-2,还有free marker。 要放倒web-inf下面的lib,这个就是dll搜索的最先的本地库路径了
2、既然上了struts2,就要通过web 配置告诉系统,filter=struts2,我的配置如何的,我要处理哪些文件(url-pattern)。看我输入错误库的名字后,加载报错找不到class “StrutsPrepareAndExecuteFilter”
first web----webapp名字,
<filter-name>struts2</filter-name>
<!-- <filter-class>org.apache.struts.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
-->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
3、到这是告诉了这个web服务器,struts2配置上了
web-inf是整个网站的root的配置,下面包括lib目录,web。xml。并列的是jsp页面,包括html页面等等。webContent就是网站的root了===webapp就会指向这个root目录的
4、开始整理struts 自身,比如struts.properties 配置字符编码,struts.xml是配置处理filter的 action的信息,action成功/失败后的跳转页面。action要放在一个指定的package 下面,package。action class 作为class的名词
然后去写这个action class,创建类可选继承自 ActionSupport
import com.opensymphony.xwork2.ActionSupport;
action被触发 执行的函数:execute(),return不同的结果,会导向到配置中的不同的页面,如果 return一个莫名其妙的string呢?
public String execute() throws Exception{
/*
hello="hello word success";
return SUCCESS;
*/
//String com.opensymphony.xwork2.Action.SUCCESS
hello="hello word failed";
return com.opensymphony.xwork2.Action.ERROR;
}
如果胡乱返回 execute()函数,结果如下:
type Status report
message No result defined for action firstweb.action.TestAction and result
description The requested resource is not available.
5、 struts2的部分全部准备完毕了,那么要看怎么触发和使用到 action的返回结果了
<%@ taglibprefix="s"uri="/struts-tags"%>
和很多网页语言一样,要使用后台代码产生的功能,需要再前端引入库, struts-tags来自struts2-core, 里面就有对应的标签了:::
<!-- a 标签 -->
<s:a action="hello">hello</s:a>
<s:form
A 标签,触发action,action的名字叫hello。在url上的体现就是跳转到 hello。action这个url路径<%@taglib prefix="s"uri="/struts-tags"%>
<!DOCTYPE htmlPUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
this is action success result page:::::
<s:property value="hello"/>
这个方法是利用property来传值,如果有多个property,就看 property的name不同 了 ;;多值返回就可以这么用的!
<s:property value="hello"/>
<s:property value="words"/>
http://localhost:8080/firstweb/hello.action
- struts 的基本练习
- Struts的基本组件
- Struts的基本介绍
- struts的基本配置
- struts 的基本用法
- 栈的基本练习
- easyui的基本练习
- Struts 2的基本流程
- Struts 2的基本配置
- Struts 2的基本流程
- Struts 2的基本配置
- Struts 2的基本流程
- 【Struts】OGNL的基本使用
- 递归的基本应用练习...
- 基本排序算法的练习
- 最基本的io练习
- 钢琴练习的基本步骤
- Struts 2.0 学习一 struts的基本原理与基本配置
- 对ContentProvider中getType方法的一点理解
- C++链接MySQL数据库实例应用
- python psutil 终止子进程
- 《鸟哥的Linux私房菜基础篇》阅读笔记——第3章、第8章
- 一起talk C栗子吧(第七十一回:C语言实例--DIY shell)
- struts 的基本练习
- VC中使用GetLastError
- odoo8 官方web客户端开发文档翻译3---Widgets Basics(基础窗口组件)
- LeetCode 005 Longest Palindromic Substring
- 架构设计:系统间通信(16)——服务治理与Dubbo 中篇(预热)
- LeetCode 列表合并问题
- 【Html】使用mailto在网页中链接Email地址
- centos下安装webbench最新版本-实现并发测试
- 黑马程序员——OC基础之点语法