SSH框架学习------struts2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSH框架学习------struts2相关的知识,希望对你有一定的参考价值。

1.总的目录

技术分享

2.所有程序

1)index.jsp很简单

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="${pageContext.request.contextPath }/helloWorld.action">helloworld!</a>
</body>
</html

2)配web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http:java.sun.com/xmll/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<!-- 配置struts2核心控制器 -->
<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>

3)配struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- 指定struts2配置文件的DTD -->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<!-- Struts2配置文件的根元素 -->
<struts>
<!-- Struts2的Action必须放在指定的包空间下定义 -->
<package name="hello" namespace="/" extends="struts-default">
<!-- 定义action,该action对应的类为cn.itcast.action.HelloWorldAction类 -->
<action name="helloWorld" class="cn.itcast.action.HelloWorldAction">
<!-- 定义处理结果和视图资源之间的映射关系 -->
<result name="success">/success.jsp</result>
</action>
</package>
</struts>

4)配Action的类,类名为:HelloWorldAction

package cn.itcast.action;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldAction extends ActionSupport {

@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}

}

5)"success"成功后返回的jsp: success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
成功!
</body>
</html>

 

























































以上是关于SSH框架学习------struts2的主要内容,如果未能解决你的问题,请参考以下文章

ssh学习笔记一:struts框架学习

[ SSH框架 ] Struts2框架学习之三(OGNl和ValueStack值栈学习)

SSH框架学习摸索记

想学习框架,SSH好还是SSM好,新手

Struts2,Hibernate,Spring框架学习总结

SSH框架之Struts2系列