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

《Struts 系列》- 入门例子

2018-01-18 00:00 281 查看
项目结构



build.gradle

apply plugin:'war'
apply plugin:'eclipse-wtp'

sourceCompatibility = 1.7

repositories{
maven{
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
}

dependencies{
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
compile group: 'javax.servlet.jsp', name: 'javax.servlet.jsp-api', version: '2.2.1'
compile group: 'org.apache.struts', name: 'struts2-core', version: '2.3.24'
}

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>
<!--
name="hello":对应请求的地址,注意没有后缀
class:为该名称,指定一个动作类
method:对应hello要执行的方法
-->
<package name="hellodemo" extends="struts-default" namespace="/">
<action name="hello" class="com.kimisme.action.HelloAction"
method="sayHello">
<result name="success">/views/success.jsp</result>
</action>
</package>
</struts>

struts.properties

# 设置为开发模式
struts.devMode=true

HelloAction.java

public class HelloAction {
/**
* 动作方法书写要求:
* 	1.public
* 	2.返回值String类型
* 	3.没有任何参数
* @return
*/
public String sayHello(){
return "success";
}
}

测试

http://localhost:8989/struts-helloworld/hello

http://localhost:8989/struts-helloworld/hello.action
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Struts