2010-05-12 81 views
0

我想更新一个简单的web应用程序,它是用struts2,jsp和标准servlet构建的。 我想重定向一个网址到一个特定的行动,但似乎无法让它正常工作。 例如,这是正确的网址是:struts动作和重定向问题

http://localhost:8080/theapp/lookup/search.action 

这里是我的web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
        "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app> 
<display-name>theapp</display-name> 

<filter> 
    <filter-name>struts2</filter-name> 
    <filter-class> 
     org.apache.struts2.dispatcher.FilterDispatcher 
    </filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>struts2</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<listener> 
    <listener-class> 
     org.springframework.web.context.ContextLoaderListener 
    </listener-class> 
</listener> 

这里是我的struts.xml:

<?xml version="1.0" encoding="UTF-8" ?> 

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration  
2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> 

在指数

<default-action-ref name="search" /> 

<action name="search" method="search" class="com.theapp.SearchAction" > 
    <result>index.jsp</result> 
    <result name="input" >index.jsp</result> 
    <result name="error" type="redirect">site_locator_mobile/error.action</result> 
</action> 

这里的问题是,如果我不指定如上正确的URL,我刚刚得到的index.jsp文件,但没有任何性能。正在处理jsp,因为信息包含在servlet中。

我想是,如果刚刚进入别人什么:

http://localhost:8080/theapp/lookup/ 

比他们将采取何种措施:

http://localhost:8080/theapp/lookup/search.action 

感谢

+0

嗯..不知道如何解决我的上述帖子中的XML,以便它们都在相同的代码块。 – Casey 2010-05-12 21:38:35

回答

0

也许你可以指定一个servlet作为欢迎文件:

<welcome-file-list> 
<welcome-file>search.action<welcom-file> 
<welcome-file-list> 

注意:有些人报告称,必须实际存在一个名为search.action的文件才能运行。

另一种选择是让你index.jsp重定向到search.action和使用其他结果的jsp:

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

编辑:也可以将过滤器映射指令直接添加到web.xml其重定向为/theapp/lookup//theapp/lookup/search.action请求

但似乎更复杂。

+0

欢迎文件方法不适用于我,因为它会重定向整个应用程序。 index.jsp也包含我需要使用的东西,它不仅仅是一个占位符。我想我可以将当​​前文件重命名为其他内容,并将一个index.jsp重定向到适当的操作。 – Casey 2010-05-12 22:07:17

0

这听起来很愚蠢,但你可以发布struts.xml文件的全部内容吗?你有没有给struts xml文件添加一个名称空间。您正在尝试查找myApp/lookup/someAction.action。我认为你应该为你的包定义一个名称空间。