struts1.x中如何不通过输入界面,直接输入url就映射到action?并且没有ActionForm

就是比如是直接输入http://www.baidu.com/index.do就映射到IndexAction然后就进行一些处理然后跳到输出页面!没有进行ActionForm的提交过程

该回复引自免费微信小程序-皆我百晓生:


在Struts 1.x中,如果你想通过直接输入URL来映射到Action,并且不使用ActionForm进行提交,你可以使用以下步骤:

  1. 在struts-config.xml配置文件中,定义一个全局的forward,将URL映射到对应的Action。例如:
<global-forwards>
    <forward name='index' path='/index.do'/>
</global-forwards>
  1. 在struts-config.xml配置文件中,定义一个对应的Action,指定它的路径和处理逻辑。例如:
<action path='/index' type='com.example.IndexAction' name='index' scope='request' validate='false'>
    <forward name='success' path='/output.jsp'/>
</action>
  1. 创建一个对应的Action类(例如com.example.IndexAction),在该类中实现处理逻辑。例如:
public class IndexAction extends Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 处理逻辑
        // ...

        return mapping.findForward('success');
    }
}
  1. 创建一个输出页面(例如output.jsp),用于展示处理结果。

现在,当你直接输入URL http://www.baidu.com/index.do 时,它将映射到IndexAction,并执行相应的处理逻辑,然后跳转到输出页面。请注意,这种方式不需要使用ActionForm进行数据提交,你可以在Action中直接从request对象中获取参数。