2010-05-12 49 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。我認爲你應該爲你的包定義一個名稱空間。