Struts2初步案例
来源:互联网 发布:qq空间模拟登录 php 编辑:程序博客网 时间:2024/06/04 18:53
Struts环境搭建
1. Struts2部署 1.引入jar包 struts2-core.jar 核心jar包 xwork.jar 核心jar包 javasist-GA 处理字节码 2.web.xml <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 核心过滤器名称 StrutsPrepareAndExcuteFlter 3.view视图页面 4.编写action 1.UserAction implement Action 2.UserAction extends ActionSupport 5.struts.xml 6.部署运行po:
public class Userinfo { private String uname; private String upwd; public String getUname() { return uname; } public void setUname(String uname) { this.uname = uname; } public String getUpwd() { return upwd; } public void setUpwd(String upwd) { this.upwd = upwd; }}Action:
public class TestAction01 implements Action { private Userinfo user; private String message; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public Userinfo getUser() { return user; } public void setUser(Userinfo user) { this.user = user; } public String execute() throws Exception { this.setMessage("你好:" + this.user.getUname()); HttpSession session= ServletActionContext.getRequest().getSession(); return "success"; }}
struts.xml:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"><struts> <!--支持动态方法调用--> <constant name="struts.enable.DynamicMethodInvocation" value="false"/> <!--修改struts.xml 不用重启容器--> <constant name="struts.devMode" value="true"/> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index"/> <!--<global-results> <result name="error">/WEB-INF/jsp/error.jsp</result> </global-results>--> <!-- <global-exception-mappings> <exception-mapping exception="java.lang.Exception" result="error"></exception-mapping> </global-exception-mappings>--> <action name="helloWord" class="cn.ljl.action.TestAction01"> <result name="success">first.jsp</result> </action> </package></struts>first.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %><%@ taglib uri="/struts-tags" prefix="s"%><html><head> <title>Struts</title></head><body><h2>Struts2 第一个案例</h2><s:property value="message"></s:property><form action="helloWord" method="post"> 用户名:<input name="user.uname"/> <input type="submit" value="提交"/></form></body></html>index.jsp:
<html><body><h2>Struts2 第一个案例</h2><form action="helloWord" method="post"> 用户名:<input name="uname"/> <input type="submit" value="提交"/></form></body></html>web.xml:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app> <display-name>Archetype Created Web Application</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>first.jsp</welcome-file> </welcome-file-list></web-app>
运行结果
阅读全文
0 0
- Struts2初步案例
- Struts2初步
- Struts2初步
- Struts2初步
- struts2初步
- Struts2案例
- struts2错误初步2
- struts2初步配置
- 初步了Struts2
- Struts2框架初步
- hibernate+struts2初步设想
- struts2的初步认识!
- struts2初步使用
- Struts2 01.初步认识
- Struts2初步认识
- 初步学习Struts2
- Struts2初步学习小结
- struts2的初步使用
- Stuts2入门案例
- 请定义一个交通工具(Vehicle)的类,其中有: 属性:速度(speed),体积(size)等 方法:移动(move()),设置速度(setSpeed(int speed)),设置体积(s
- 写一个生活中常见的死锁
- 为什么使用maven
- 基于数组的队列实现
- Struts2初步案例
- codeforces 867 E Buy Low Sell High(优先队列)
- DL multi GPUs problem
- 含有不同正整数的数组是否可以分成两个和相等的数组JS算法实现
- 错失VIPKID,俞敏洪组团来教育领域“淘宝”
- 在一线城市,有多少人正在“被创业”?
- 比较大小
- ResNet残差网络的理解
- Struts 入门