Struts gradle 第一個(gè)hello world程序

github項(xiàng)目地址,https://github.com/bsqql123/structs-demo
建議clone下來,在本地進(jìn)行調(diào)試。

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

整個(gè)項(xiàng)目結(jié)構(gòu)如下:

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>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容