一,用到文件
1.输入页面
input1.jsp页面
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<html>
<head>
<title>JSP for HelloWorldForm form</title>
</head>
<body>
<html:form action="/helloWorld2">
msg : <html:text property="msg"/><html:errors property="msg"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
threeInput.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'input3.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="<%=basePath%>threeInput.do" method="post">
欢迎语:<input type="text" name="msg" value="" />
<input type="submit" name="method" value="insert" />
<input type="submit" name="method" value="update" />
<input type="submit" name="method" value="delete" />
</form>
</body>
</html>
2.输出页面
show.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'show.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<%
String str = (String)request.getAttribute("helloWorld");
%>
<body>
你输入的欢迎语1是:${helloWorld}<br>
你输入的欢迎语2是:<%=str%>
</body>
</html>
3.ActionForm类
public class HelloWorldForm extends ActionForm {
/*
* Generated fields
*/
/** msg property */
private String msg;
/*
* Generated Methods
*/
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
/**
* Returns the msg.
* @return String
*/
public String getMsg() {
return msg;
}
/**
* Set the msg.
* @param msg The msg to set
*/
public void setMsg(String msg) {
this.msg = msg;
}
}
4.action类
[1]HelloWorld1Action 类
public class HelloWorld1Action extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String str = "hello zhao在";
request.setAttribute("helloWorld", str);
return mapping.findForward("show");
}
}
[2]HelloWorld2Action 类
public class HelloWorld2Action extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
HelloWordForm helloWordForm = (HelloWordForm) form;// TODO Auto-generated method stub
String msg = helloWordForm.getMsg();
request.setAttribute("helloWorld", msg);
//response.setCharacterEncoding("utf-8");
//response.setContentType("text/html;charset=utf-8");
return mapping.findForward("show");
}
}
[3]ThreeInputAction类
public class ThreeInputAction extends DispatchAction {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
HelloWordForm helloWordForm = (HelloWordForm) form;// TODO Auto-generated method stub
return null;
}
}
二.配置struts-config.xml
1.无输入页面,只有action和输出
<action-mappings >
<action path="/helloWorld1" type="com.zhao.struts.action.HelloWorld1Action">
<forward name="show" path="/WEB-INF/jsp/show.jsp" />
</action>
</struts-config>
2.有输入页面,无bean,action就要用 request.getParameter("msg");拿参数
3.有bean
<form-beans >
<form-bean name="helloWorldForm" type="com.zhao.struts.form.HelloWorldForm" />
</form-beans>
<action-mappings >
<action
attribute="helloWorldForm"
name="helloWorldForm"
path="/helloWorld2"
scope="request"
type="com.zhao.struts.action.HelloWorld2Action"
validate="false">
<forward name="show" path="/WEB-INF/jsp/show.jsp" />
</action>
</action-mappings >
4.输入页面的配置
[1]直接/form/input1.jsp浏览就不用配置
[2]
<!--struts能生成-->
<action forward="/WEB-INF/jsp/input1.jsp" path="/input2" />
<action include="/WEB-INF/jsp/input1.jsp" path="/input3" />
<!--struts不能生成-->
<action
path="/input4"
type="org.apache.struts.actions.ForwardAction"
parameter="/WEB-INF/jsp/input1.jsp" />
5.多按钮的配置
<action
attribute="helloWorldForm"
name="helloWorldForm"
parameter="method"
path="/threeInput"
scope="request"
type="com.zhao.struts.action.ThreeInputAction">
<forward name="show" path="/WEB-INF/jsp/show.jsp" />
</action>
分享到:
相关推荐
@className:指定当前控制器的配置类.默认为org.apache.struts.config.ControllerConfig @contentType:指定相应结果的内容类型和字符编码 @locale:指定是否把Locale对象保存到当前用户的session中,默认为false @...
从 Struts1 升级到 Struts2: 1、Struts1 里使用 ActionServlet 作为控制器; Struts2 使用了一个过滤器作为控制器 2、Struts1 中每个 ...5、Struts2 在页面里使用 OGNL 来显示各种对象模型, 可以不再使用 EL 和 JSTL
3.控制器采用action开发,替代传统的servlet,直接跳转页面返回一个字符串即可,需配置struts.xml对应的jsp。 4.struts2,可以直接对表单提交的数据封装成对象,简洁!当然需要在web.xml中配置核心filter—...
功能: 在登录页面login.jsp中输入用户名admim和密码123456后,单击...3. 设置核心控制器(配置web.xml) 4. 创建业务逻辑控制器(Action) 5. 创建视图页面 6. 创建struts.xml配置Action 7. 部署和运行struts2项目
11.4.7 编写Struts的配置文件struts-config.xml 11.4.8 编写Spring的配置文件spring-config.xml 11.4.9 配置web.xml 11.4.10 启动Tomcat运行示例 11.5 小结 第十二章 使用Hibernate快速实现持久层处理 12.1 ...
本书完整介绍了Struts框架结构,涵盖了设计、数据校验、数据库访问、动态页面生成、本地化、Struts配置以及其他一些重要的方面。书中还介绍了如何同时使用JSP标签和Velocity模板,并仔细介绍了Struts体系结构以及...
第一章 配置环境 第二章 HelloWorld你的第一个Struts程序 第三章 MVC概述 第四章 Model模型 第五章 View页面视图 第六章 Controller控制器 第七章 使用Struts连接池 第八章 Struts的异常处理 第九章 Struts的国际化 ...
11.4.7 编写Struts的配置文件struts-config.xml 11.4.8 编写Spring的配置文件spring-config.xml 11.4.9 配置web.xml 11.4.10 启动Tomcat运行示例 11.5 小结 第十二章 使用Hibernate快速实现持久层处理 12.1 ...
3.初识struts2配置文件 4 (1).web.xml文件 4 (2).struts.xml文件 4 (3).struts.properties(参default.properties) 4 (4)struts-default.xml 4 (5)其它配置文件 4 4.让MyEclipse提示xml信息 4 5.如何...
11.4.7 编写Struts的配置文件struts-config.xml 11.4.8 编写Spring的配置文件spring-config.xml 11.4.9 配置web.xml 11.4.10 启动Tomcat运行示例 11.5 小结 第十二章 使用Hibernate快速实现持久层处理 12.1 ...
struts2 标签库使用说明.Struts2中通用标签可以分为二类:控制标签和数据标签。控制标签用于呈现页面时控制执行流程,数据标签用于访问值栈中的数据。
3.2 使用配置文件struts.xml实现页面导航定义 38 3.3 使用Action类控制导航业务数据 40 3.4 使用ActionSupport进行校验 42 第4章 另一Struts2核心技术:拦截器 47 4.1 拦截器在Struts2中的缺省应用 47 4.2 拦截器...
8.1.1 页面上:如何使用自定义结果组件构建Struts 2 Ajax应用程序 171 8.1.2 实现JSON结果类型 173 8.2 常用的结果类型 180 8.2.1 RequestDispatcher,也叫做dispatcher 180 8.2.2 ServletRedirectResult,也叫做...
Struts 2.0框架中出现的许多特性旨在让Struts更容易使用: · 改进的设计: 与Struts 1相比,...· 易于定制的控制器: Struts 1允许请求处理程序可按照模块来定制,在Struts 2中,需要的话,可以按照动作来定制请求处理
包括配置环境 第一个Struts程序 MVC概述 Model模型 View页面视图 Controller控制器 连接池 异常处理 国际化等
系统的基本业务流程是: 在表示层中,首先通过JSP页面实现交互界面,负责传送请求(Request)和接收响应(Response),然后Struts根据配置文件(struts-config.xml)将ActionServlet接收到的Request委派给相应的Action...
struts1的几个核心组件是值得我们注意的: 1 、ActionServlet(核心控制器)。 2、RequestProcessor类(处理异常的核心组件)。 3、ActionForm(接收页面中传过的数据)。 4、Action(是控制器,主要是从ActionForm中...
直白来说,Struts用于页面显示,Spring控制流程,Hibernate连接数据库。 下面说一下配置顺序: 一.新建WEB工程。 二.导入Struts1.2。 三.导入Spring。