struts入门案例
来源:互联网 发布:淘宝开店教程全集30 编辑:程序博客网 时间:2024/06/06 01:31
一 创建一个Web project
名称为HelloWorld,创建界面如下:
二 安装struts
截图如下:
三 生成项目后,框架自动生成过滤器
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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_3_0.xsd";>
<display-name></display-name>
<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>*.action</url-pattern>
</filter-mapping></web-app>
四 框架自动生成struts
<?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>
</struts>
五 创建action
截图如下:
package com.cakin.action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport {
@Override
public String execute() throws Exception {
System.out.println("执行Action");
return SUCCESS;
}
}
六 配置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="default" namespace="/" extends="struts-default">
<action name="helloworld" class="com.cakin.action.HelloWorldAction">
<result>/result.jsp</result>
</action>
</package>
</struts>
七 创建result.jsp文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'result.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>
This is my JSP page. <br>
</body>
</html>
八 测试
阅读全文
0 0
- Struts入门案例
- struts入门案例
- Struts 入门案例
- struts入门案例 登录
- Struts入门案例
- Struts 2入门案例
- struts入门案例
- Struts(2)Struts快速入门案例和使用filter配合Struts,解决中文乱码问题
- 关于struts与spring整合的一个小案例入门
- struts案例的struts.xml
- 入门案例
- struts+spring 整合案例
- struts ajax使用案例
- struts+hibernate综合开发案例
- Struts案例动作类
- Struts案例1
- struts综合案例
- Hibernate+Struts综合案例
- Local variable name 'pay_status' doesn't match regex '[a-z][A-Za-z\d]*'
- Struts2 开发准备
- Go面向对象编程之接口
- MapReduce之WordCount单词计数(上)
- javascript基本数据类型总结
- struts入门案例
- Python入门(八)
- MapReduce之WordCount单词计数
- 利用MapReduce进行排序
- 二叉树各种基本运算的算法
- Struts访问Servlet API
- LintCode 85. 在二叉查找树中插入节点
- Action搜索顺序-Struts2深入
- Struts2的工作原理及文件结构