Struts2: How do I tell my index.jsp to forward to a struts2 action?

南楼画角 提交于 2020-01-02 07:06:25

问题


Oftentimes when I see an index.jsp on a web application it just forwards to another url like login.jsp such as

<jsp:forward page="login.jsp" />

When using struts2, I want a similar index.jsp but I want it to forward to an action. How do I do this?


回答1:


You can use plain HTML if you want

Between your head tags use:

 <META HTTP-EQUIV="Refresh" CONTENT="1;URL=Login.action">

This will redirect to myCOntext/Login.action

If Login is behind a name space you wil need to include that in the URL




回答2:


Scriplet:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<%  
response.sendRedirect("/Project/namespace/Login.action");
%> 

I use it with Struts2 and it works.




回答3:


Try this:

<META HTTP-EQUIV="Refresh" CONTENT="0;URL=welcomeLink.action">

This is also a working one,

<%  
response.sendRedirect("welcomeLink.action");
%> 

But in my experience it will work only when it is in index page, or any other page which is loaded as first page.

If I put response.sendRedirect in any successor page it will not work Reffer this question



来源:https://stackoverflow.com/questions/3186402/struts2-how-do-i-tell-my-index-jsp-to-forward-to-a-struts2-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!