struts动作和重定向的问题

时间:2010-05-12 21:38:04

标签: java struts2

我正在尝试更新使用struts2,jsp和标准servlet构建的简单Web应用程序。 我正在尝试将网址重定向到特定操作,但似乎无法让它正常工作。 例如,正确的网址是:

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文件,但是没有正在处理index.jsp中的任何属性,因为信息是包含在servlet中。

如果有人刚进入,我想要的是:

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

他们将被带到:

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

由于

2 个答案:

答案 0 :(得分: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

但似乎更复杂。

答案 1 :(得分:0)

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

相关问题