熟悉struts2MVC模式之用模型驱动传参的例子
来源:互联网 发布:男女对唱的网络歌曲 编辑:程序博客网 时间:2024/05/20 03:06
web.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<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></web-app>
model层(pojo普通java类):
package com.bjsxt.model;
public class Stu {
private int id;
private String name;
private String pwd;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}
control控制层(action类):
package com.bjsxt.action;
import com.bjsxt.model.Stu;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class StuAction extends ActionSupport implements ModelDriven<Stu> {
public Stu getStu() {
return stu;
}
public void setStu(Stu stu) {
this.stu = stu;
}
private Stu stu = new Stu();
@Override
public Stu getModel() {
return stu;
}
@Override
public String execute() throws Exception {
System.out.println(stu.getId());
System.out.println(stu.getName());
System.out.println(stu.getPwd());
return "stu";
}
}
显示层(view)登陆页面:
<%@ 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 'stulogin.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>
<h3 align="center">stu_info</h3>
<form action="StuAction" method="post">
ID号:<input type="text" name="id"><br>
姓名:<input type="text" name="name"><br>
密码:<input type="password" name="pwd"><br>
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</body>
</html>
显示层(view)输出页面:
<%@ 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 'stu.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>
<h3 align="center">stu_collect</h3>
<p align="center">
ID号:<%=request.getParameter("id") %><br>
姓名:<%=request.getParameter("name") %><br>
密码:<%=request.getParameter("pwd") %><br>
</p>
</body>
</html>
配置文件struts.xml
<?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="a" namespace="/" extends="struts-default">
<action name="User" class="com.bjsxt.action.User">
<result name="user">user.jsp</result>
</action>
<action name="StuAction" class="com.bjsxt.action.StuAction">
<result name="stu">stu.jsp</result>
</action>
</package>
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
</struts>
- 熟悉struts2MVC模式之用模型驱动传参的例子
- 熟悉struts2MVC模式之用属性驱动传参例子
- 对Struts2mvc的理解
- SpringMVC和Struts2MVC的区别
- Linux驱动模型的编程模式
- 关于在vp下dof模型驱动的简单例子
- 关于在vp下dof模型驱动的简单例子
- 关于在vp下dof模型驱动的简单例子
- struts2的模型驱动(推荐使用)、属性驱动模式
- 使用模型驱动开发和基于模式的工程来设计 SOA之第 4 部分
- 熟悉oc面向对象的小例子
- 设备驱动的艺术之旅 - 简单网卡驱动模型
- WDM模式驱动简单例子
- 设备模型之驱动
- struts2之模型驱动
- struts2两种Action驱动模式之Model-Driven(模型驱动)
- 有人研究过凤之焚的MimeFilter例子吗 或者熟悉网页内容过滤技术的请进。MimeFilter Bu
- .NET程序员应该熟悉的开发模式
- HDOJ2043 密码
- 模块加载
- SQLite数据库增删改查操作
- Java邮件开发-----JavaMail(一)
- 杭电OJ 题 2673 shǎ崽 OrOrOrOrz 解题报告
- 熟悉struts2MVC模式之用模型驱动传参的例子
- 【Boost】boost::to_upper_copy详解
- 陶醉在音乐的国度,我如痴如醉
- 12-12-09记录
- Hdu 1423 Greatest Common Increasing Subsequence
- 杨辉三角
- iOS开发之使用lipo命令制作模拟器与真机通用静态库
- Servlet的几种跳转
- Lua 学习开篇