简体   繁体   English

在struts中使用href调用Action in Action类

[英]Invoke a Function in Action class with href in struts

I am trying to load a file on click of a href on my JSP page. 我正在尝试在JSP页面上单击href来加载文件。 The file is not stored within the directory of the web server. 该文件未存储在Web服务器的目录内。 Therefore, on clicking the href I may need to invoke an action which would read the file, copy it to the webserver in a temporary directory and then show to the user. 因此,在单击href时,我可能需要调用一个操作,该操作将读取文件,将其复制到临时目录中的Web服务器,然后显示给用户。 (The file could be msword, pdf, html etc). (文件可以是msword,pdf,html等)。

I have been able to find how an action can be invoked in struts 2 using . 我已经能够找到如何使用Struts 2调用动作。 But how can this be achieved in struts 1.2 ? 但是如何在struts 1.2中实现呢?

Only other solution I can think of is redirecting to another JSP page and then invoking its action classes to do the rest. 我能想到的唯一其他解决方案是重定向到另一个JSP页面,然后调用其操作类来完成其余的工作。 But is it possible to call an action directly from an href ? 但是是否可以直接从href调用动作?

It is possible. 有可能的。 Here's how I call my Struts action from href links - 这是我通过href链接调用Struts操作的方式-

<a href="YourActionsClass.do?method=execute">some link text</a>

and in your struts-config.xml add 并在您的struts-config.xml中添加

parameter=method

execute is the method inside your action class which extends org.apache.struts.action.Action execute是您的操作类内部的方法,该方法扩展了org.apache.struts.action.Action

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM