Struts gradle 第一個hello world程序

github項目地址,https://github.com/bsqql123/structs-demo
建議clone下來,在本地進行調試。

參考文章:https://www.mkyong.com/struts2/struts-2-hello-world-example/

整個項目結構如下:

build.gradle配置

group 'me.iceblue'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'war'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {

    testCompile group: 'junit', name: 'junit', version: '4.12'

    /*jsp*/
    providedCompile 'javax.servlet:javax.servlet-api:3.0.1'

    // https://mvnrepository.com/artifact/org.apache.struts/struts2-core
    compile group: 'org.apache.struts', name: 'struts2-core', version: '2.5.5'

}

web.xml配置

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

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

<struts>

    <constant name="struts.devMode" value="true"></constant>
    <constant name="struts.i18n.encoding" value="UTF-8"></constant>
    <constant name="struts.locale" value="zh_CN"></constant>

    <package name="hurricane" extends="struts-default">
        <action name="loginAction" class="controller.IndexController" method="execute">
            <result>
                /result.jsp
            </result>
        </action>
    </package>
</struts>

IndexController.java如下

package controller;

import com.opensymphony.xwork2.ActionSupport;

/**
 * Created by iceblue on 2017/2/17.
 */


public class IndexController extends ActionSupport {
    public String Name;

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }

}

result.jsp如下

<%--
  Created by IntelliJ IDEA.
  User: iceblue
  Date: 2017/2/17
  Time: 0:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>

  <h1>This is the result.jsp</h1>

  </body>
</html>
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容