java struts2配置_java之struts2的配置讲解(2)

基础上,进行下列操作

1.结构对比

原来的项目结构图

a7fc1a4ee2e7e835783c5927571be4f0.png

现在的结构图

dbdf98f3c6491c5f03dcd0262d36acce.png

即从结构上可以看出,在HelloStruts项目中增加了config 文件夹(Source Folder) 及user.xml 文件

2.修改配置文件,使struts.xml 中包含 user.xml 配置文件

struts.xml

/p>

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

"http://struts.apache.org/dtds/struts-2.3.dtd">

user.xml

/p>

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

"http://struts.apache.org/dtds/struts-2.3.dtd">

/index.jsp

3.修改 HelloAction 类,增加 hello 方法

public classHelloAction {struts2的处理方法 都是 public String的 默认执行execute,并且处理方法没有参数

publicString execute(){

System.out.println("请求被接收了...");return "success";

}publicString hello(){

System.out.println("hello");returnAction.SUCCESS;

}

}

因为在配置文件中,指定了hello方法,所以请求会进入hello方法

4.运行程序,并且在浏览器输入网址验证

网址:http://localhost:8080/Hello/sys/hello.action

浏览器显示

114b946b4c624dce6f65c331ff599d37.png

myeclipse中的console显示

f1a34d3c9b7ae86b12a8e18dba3b0e30.png

说明请求成功被接收了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值