框架是什么?

1.应用程序的半成品。

2.可重用行公共的结构。

3.按一定规则组织的一组组件。

model2 其实并不是一种全新的概念,很对人指出model2其实正好是经典的"模型(model) - 控制器(controller)- 视图(view)"

即mvc设计模式(mvc设计模式最早是从smalltalk语言中的mvc框架抽象出来的)。对于javaweb开发人员,mvc设计模式和model2模型是等效的。

model2在很多地方还被称为"基于action的框架";

struts的简单配置。

工具(MyEclipse)→ 创建web工程 → 右击工程名字选到myeclipse,然后在添加,add struts.... 

创建完成后,工具会自动创建好struts.xml 还会配置好WEB-INF下的web.xml,!ps:web,xml.文件不需要修改

 package com.obtk.struts;

 import java.util.Map;

 import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext; /**
* 计算两个叔的结果
* */
public class add implements Action {
private int x; // 第一个数
private int y; // 第二个数
private int cunot; // 结果
private String op; // 方法 public String execute() throws Exception {
String reslt = "defeated";
// 如果op等于add,那么就是相加
if (this.getOp().equals("add")) {
this.setCunot(this.getX() + this.getY());
reslt = "successs";
}
// 保存放map里面。作用域是request
Map<String, Object> request = (Map) ActionContext.getContext().get(
"request");
request.put("count", getCunot());
return reslt;
} public int getX() {
return x;
} public void setX(int x) {
this.x = x;
} public int getY() {
return y;
} public void setY(int y) {
this.y = y;
} public String getOp() {
return op;
} public void setOp(String op) {
this.op = op;
} public int getCunot() {
return cunot;
} public void setCunot(int cunot) {
this.cunot = cunot;
} }

实现Action 接口

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="test" extends="struts-default" namespace="/">
<action name="add" class="com.obtk.struts.add">
<result name="successs">/successs.jsp</result>
</action>
</package>
</struts>

配置struts.xml的代码

 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>结果页面</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">
</head>
<body>
计算结果 ${param.x }+${param.y }=${count}
</body>
</html>

successs.jsp页面代码

敲完代码.在浏览器敲 http://localhost:8080/Struts1/add.action?x=10&y=20&op=add 就会显示结果,

入门struts2.0 ,今天刚刚学的,勿喷,谢谢。

                         218786602QQ群,欢迎大家一起讨论。 

入门struts2.0的更多相关文章

  1. Struts2.0笔记二

    Mvc与servlet 1.1   Servlet的优点 1.  是mvc的基础,其他的框架比如struts1,struts2,webwork都是从servlet基础上发展过来的.所以掌握servle ...

  2. struts2.0整合json

    框架:struts2.0+hibernate2+spring 今天写代码时,需要用到json,我就直接加了两个jar包:json-lib-2.1-jdk15.jar,struts2-json-plug ...

  3. [转]初探Struts2.0

    本文转自:http://blog.csdn.net/kgd1120/article/details/1667301 Struts作为MVC 2的Web框架,自推出以来不断受到开发者的追捧,得到用广泛的 ...

  4. Struts2.0 去掉action后缀名

    刚刚接触Struts2.0,发现默认请求都会带着后缀名:action 就如下图,url地址中会暴露login.action(请原谅struts拼写错误..) 作为一个URL简洁爱(chu)好(nv)者 ...

  5. (转)struts2.0配置文件、常量配置详解

    一.配置: 在struts2中配置常量的方式有三种: 在struts.xml文件中配置 在web.xml文件中配置 在sturts.propreties文件中配置 1.之所以使用struts.prop ...

  6. struts2.0 struts.xml配置文件详解

    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quo ...

  7. Struts2.0+Spring3+Hibernate3(SSH~Demo)

    Struts2.0+Spring3+Hibernate3(SSH~Demo) 前言:整理一些集成框架,发现网上都是一些半成品,都是共享一部分出来(确实让人很纠结),这是整理了一份SSH的测试案例,完全 ...

  8. struts2.0中struts.xml配置文件详解

    先来展示一个配置文件 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration ...

  9. struts2.0 s标签_小小鸟_百度空间

    struts2.0 s标签 1. Struts2页面开发中常用标签使用说明 1.1.往action里传值的使用方式: <input name="userName" type= ...

随机推荐

  1. php : RBAC 基于角色的用户权限控制-表参考

    --管理员表 CREATE TABLE `sw_manager` ( `mg_id` int(11) NOT NULL AUTO_INCREMENT, `mg_name` varchar(32) NO ...

  2. [记录][python]python爬虫,下载某图片网站的所有图集

    随笔仅用于学习交流,转载时请注明出处,http://www.cnblogs.com/CaDevil/p/5958770.html 该随笔是记录我的第一个python程序,一个爬去指定图片站点的所有图集 ...

  3. AngulerJS小知识点二

    AngularJS与其他JavaScript框架最主要的区别在于,控制器并不合适用来执行DOM操作.格式化或数据操作,以及除存储数据模型以外的状态维护操作.他只是视图和$scope之间的桥梁. 过滤器 ...

  4. C# 文件类型

    C# 中一些常用文件类型: designer.cs 是窗体设计器生成的代码文件,作用是对窗体上的控件做初始化工作(在函数InitializeComponent()中).VS2003以前都把这部分代码放 ...

  5. IntrospectorCleanupListener作用

    <!--web.xml--><listener> <listener-class>org.springframework.web.util.Introspector ...

  6. js跨域_jsonP

    $.ajax("url", type:"get", dataType:"jsonp", jsonp:"callback" ...

  7. [官方软件] Easy Sysprep v4.3.29.602 【系统封装部署利器】(2016.01.22)--skyfree大神

    [官方软件] Easy Sysprep v4.3.29.602 [系统封装部署利器](2016.01.22) Skyfree 发表于 2016-1-22 13:55:55 https://www.it ...

  8. a.redhat系统如何卸载默认jdk

    Redhat系统安装之后,会默认有openjdk在安装(下图已经是卸载掉了) 这个openjdk下面的需要进行卸载,你可以通过命令进行卸载,例如首先查看JDK,然后默认直接通过rpm命令进行卸载L 卸 ...

  9. Python之路 day2 字符串/元组/列表/字典互转

    #-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ' ...

  10. MySQL数据库常用命令

    1.连接mysql数据库:mysql -u用户名 -p密码; 2.创建数据库:create database 数据库名称; 3.删除数据库:drop database 数据库名称; 4.使用数据库:u ...