Struts2第一天

第一节: Struts2简介

     主页: http://stuts2.apache.org/

     在用户请求和模块化处理方面以及页面的展现这块,struts2发挥的屌炸天的作用;

     相对于传统的Jsp+Servlet模式,Struts2更适合企业级团队开发,方便系统的维护;

     最新版本:  2.3.16



第二节: Struts2 Hello World


struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    
  <package name="helloWorld" extends="struts-default">
       <action name="hello" class="com.java1234.action.HelloWorldAction">
           
 <result name="success">helloWorld.jsp</result>
       </action>
</package>

</struts>

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" 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">
  <display-name>HeadFirstStruts2Chap01</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.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>/*</url-pattern>
  </filter-mapping>



</web-app>

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>
Struts2大爷你好!
</body>
</html>

action

package com.java1234.action;

import com.opensymphony.xwork2.Action;

public class HelloWorldAction implements Action{

     @Override
     public String execute() throws Exception {
          System.out.println("执行了Action的默认方法");
          return SUCCESS;
     }

}


你可能感兴趣的:(Struts2第一天)