SSH框架学习------struts2(一)

1.总的目录

SSH框架学习------struts2(一)

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>

上一篇:Linux下PHP开发环境搭建


下一篇:linux C/C++开发环境搭建指南