您的位置:首页 > 编程语言 > Java开发

第一个Struts程序(Helloworld)

2016-10-29 08:58 295 查看
 

1:index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML >

<html>

  <head>

    <title>HelloWorld</title>

  </head>

  <body>

    this is my first Struts2 Demo!

  </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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <display-name>Struts2Env</display-name>

   <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>

  

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

</web-app>

 3:struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <package name="default"  namespace="/" extends="struts-default">

    <action name="hello" class="cn.com.mooc/MyAction">

    <result name="success">/hello.jsp</result>

    </action>

    </package>

</struts>

 4:Action(控制器)

package cn.com.mooc;

import com.opensymphony.xwork2.ActionSupport;

public class MyAction extends ActionSupport {

private static final long serialVersionUID = 1L;

   @Override

   public String execute()throws Exception{
  return SUCCESS;

   }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: