这是我的index.jsp文件:
HOME这是我的struts.xml:
${url}
这是我的动作类:
public class UrlAction extends ActionSupport {
private String url;
public void setUrl(String url) {
this.url = url;
}
public String getUrl(){
return url;
}
public String execute() throws Exception {
System.out.println("Entering execute() of Action");
url = "https://www.google.com/";
return "redirect";
}
}
因此,当我运行index.jsp时,它应该将我重定向到https://www.google.com,但我没有得到它.正在打印“输入执行的执行()”.这意味着它将进入Action类.如果我做错了,请纠正我.
解决方法:
你应该改变
${url}
至
${url}
和
至
使其有效;
但是,即使这样做,您也不会重定向您的页面,因为这不是< s:action>标签,according to the documentation:
This tag enables developers to call actions directly from a JSP page by specifying the action name and an optional namespace. The body content of the tag is used to render the results from the Action. Any result processor defined for this action in struts.xml will be ignored, unless the executeResult parameter is specified.
我想你可能会在你的标签内看到重定向的谷歌页面(修改后)
编辑
你应该准确地描述你想要达到的目标;你开始问一个关于< s:action>的问题.标签,但我很确定这不是你需要的(尽管我还没有完全理解你想要的东西,除了某个地方的“重定向”)
如果您想在打开页面时立即重定向,只需使用< s:url>标记以将url挂载到您的操作,并将其放入更改位置的javascript脚本中:
location.href = "";
(但这很奇怪,因为如果你需要在来自另一个动作时重定向,没有理由从JSP页面传递,只需使用redirectAction结果而不是重定向结果)
如果您想在按下按钮时重定向,请使用< s:submit>标签:
首先确定并描述您的目标,然后获取有助于您做到这一点的技术的信息.
标签:java,url,struts2,jsp,redirect
来源: https://codeday.me/bug/20190725/1534328.html
2056




被折叠的 条评论
为什么被折叠?



