java重定向不起作用_java – 重定向在struts2中不起作用

这是我的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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值