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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容