Struts2.0入门
来源:互联网 发布:大番长数据修改器 编辑:程序博客网 时间:2024/05/19 03:22
版本:eclipse 3.3,myeclipse 6.0,tomcat 6.0
在myeclipse中新建项目StrutsDemo,在struts官网下载struts2.0 jar包
并将jar包拷贝到项目lib中
若myeclipse版本为6.5则可以直接导入struts2.0包
核心包:commons-logging-api-1.1.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.8.jar
xwork-2.0.3.jar
在com.shiryu.demo包中新建HelloAction.java
package com.shiryu.demo;
import com.opensymphony.xwork2.ActionSupport;
public class HelloAction extends ActionSupport {
private String msg;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
if("kava".equalsIgnoreCase(msg)) {
return"suc";
} else {
return"err";
}
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
System.out.print("*******************");
this.msg = msg;
}
}
配置web.xml文件
<?xml version="1.0"encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</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>
</web-app>
配置struts.xml(struts.xml在src文件夹中)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD StrutsConfiguration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="zhaiyu"namespace="/" extends="struts-default">
<action name="hello"class="com.shiryu.demo.HelloAction">
<resultname="suc">
/hello.jsp
</result>
<resultname="err">
/errors.jsp
</result>
</action>
</package>
</struts>
新建index.jsp
<%@ page language="java" import="java.util.*"pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<form action = "hello.action" method ="post">
输入内容:<input type="text" name="msg" />
<input type="submit" value="提交"/>
</form>
</body>
</html>
新建hello.jsp
<%@ page language="java" import="java.util.*"pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
输入内容为:<s:property value="msg"/>
</body>
</html>
新建errors.jsp
<%@ page language="java" import="java.util.*"pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'errors.jsp' starting page</title>
</head>
<body>
输入内容有错误!!!!
</body>
</html>
- Struts2(0):Struts2框架入门
- struts2.0入门
- Struts2.0入门
- Struts2.0 入门,namespace
- struts2.0入门级例子
- struts2.0入门级例子
- struts2.0入门与配置
- Struts2入门
- struts2 入门
- struts2入门
- struts2-入门
- struts2入门
- struts2入门
- Struts2入门
- struts2入门
- Struts2入门
- struts2 入门
- struts2-入门
- 3.5.2 使用组件
- 转载一篇Unix操作命令大全
- jxl对Excel的读、写、更新以及插入图片(含代码实例)
- Windows Phone 7的多任务解决方案
- 回调函数
- Struts2.0入门
- debian 5.04 lenny 配置DNS服务器
- linux命令
- [转]新概念英语学习视频教程1-4册
- SD操作学习(转)
- Struts1.2中的action配置(使用DynaActionForm)
- 关于MYSQL 远程登录的授权方法 命令
- 非真实渲染(一)
- Maven antrun plugin调用Ant Optional Task