在struts.xml中配置对action配置

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

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

<struts>
<!--
package表示一个包
name:包名(唯一)
extends:继承
action:相当于servlet映射路径 name:action映射
class:处理请求的类
method:处理请求的方法
result:结果,返回处理的结果
http://localhost:8080/项目名/hello
-->
<package name="p1" extends="struts-default">
<action name="hello" class="org.ccit.com.web.action.HelloAction" method="sayhello">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>

helloaction.java

package org.ccit.com.web.action;
public class HelloAction {
public String sayhello() throws Exception {
System.out.println("sayhello方法被调用");
return "success";
}
}

success.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
hello action 方法sayhello方法返回的页面、
</body>
</html>