2015-03-03 63 views
0

我做我的struts2的應用程序,所以我是儘量包括Struts的不斷struts.action.extensionJSP擴展,但其顯示找不到網頁error.Here是代碼是我的嘗試,struts.action.extension爲「jsp的」不工作

的struts.xml:

<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
    "http://struts.apache.org/dtds/struts-2.0.dtd"> 
    <struts> 
    <!-- <constant name="struts.devMode" value="true"></constant>--> 
    <constant name="struts.action.extension" value="jsp"/> 
    <package name="default" namespace="/" extends="struts-default" > 
    <action name="LoginClass" class="com.struts2.LoginCheckingClass" method="execute"> 
    <result name="success">/LoginSuccessPage.jsp</result> 
    <result name="input">/Home.jsp</result> 
    </action> 
    </package> 
    </struts> 

回到Home.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 
<%@ taglib prefix="s" uri="/struts-tags" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Insert title here</title> 
</head> 
<body> 
<s:form action="LoginClass" method="post"> 

<s:textfield name="Uname" label="User Name" /> 

<s:textfield name="Pwd" label="Password" /> 

<s:submit Value="Login" /> 

</s:form> 

</body> 
</html> 

我們B.XML:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
version="2.5"> 
    <display-name>Struts2Application</display-name> 
    <welcome-file-list> 
    <welcome-file>home.jsp</welcome-file> 
    </welcome-file-list> 
    <filter> 
    <filter-name>Struts2</filter-name> 
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 
    </filter-class> 
    </filter> 
    <filter-mapping> 
    <filter-name>Struts2</filter-name> 
    <url-pattern>/*</url-pattern> 
    </filter-mapping> 
</web-app> 

應用程序運行完美(http://localhost:8080/Struts2Application/LoginClass.action)當我刪除<constant name="struts.action.extension" value="jsp"/>,但我想在http://localhost:8080/Struts2Application/LoginClass.jsp運行。我看過很多鏈接,但沒有任何幫助。

注:我用struts 2.3.20

有人告訴我該怎麼解決這個問題?

更新:

看到我的應用程序結構在這裏。

enter image description here

+0

你'Home.jsp'文件不' home.jsp'。在你的屏幕截圖中,有'html'擴展名而不是'jsp',所以很顯然它不適用於'LoginClass.jsp'。 – 2015-03-03 14:49:19

+0

一般來說,您需要在點擊歡迎頁面後重定向到操作。現在,您正嘗試點擊'.../Home.jsp'網址,該網址將被解釋爲操作命中,但您沒有使用「主」名稱的操作。 – 2015-03-04 11:04:03

回答

0

,如果你要運行該本地主機:8080 /應用/ LoginClass.jsp(我假設的index.jsp爲默認頁),您的web.xml文件看起來像如下圖所示

<welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 

然後包括從index.jsp重定向鏈接到App/LoginClass.jsp。

否則,按照這個

<welcome-file-list> 
    <welcome-file>App/LoginClass.jsp</welcome-file> 
</welcome-file-list> 

上述變化必須通過保持

<constant name="struts.devMode" value="true"> 

我不知道這是否是有關您的問題進行,

順便說一句,你爲什麼想用struts.action.extension?最新的要求是什麼?

編輯:

你可以試試這個... 保持搜索結果頁這樣的文件夾內,

<result name="success">tempFolder/LoginSuccessPage.jsp</result> 
<result name="input">tempFolder/Home.jsp</result> 

然後使用

<constant name="struts.action.extension" value="jsp"/> 

,並執行program..results來?

我認爲,如果我們使用「struts.action.extension」 ,,對存在於「根目錄」的結果這個頁面沒有找到是發生.. 親切測試我的上述情況下,讓我知道是否能夠正常工作

編輯2:
從你的屏幕截圖
你有2個斜線這裏 - 網頁//回到Home.jsp 將其更改爲頁/回到Home.jsp
現在嘗試運行

編輯3:
嘗試從Home.jsp..append .action通過這existi NG動作

<s:form action="LoginClass.action" method="post"> 


和執行..抱歉,我不能嘗試執行程序here..i將有一個更好的主意,如果我執行

+0

我覺得你沒有理解我的問題。看看這個「struts.action.extension來爲Struts2應用程序配置URL後綴。默認後綴是.action,但有時我們可能想把它改成.do或其他東西」,所以我嘗試更改網址loginclass.jsp而不是loginclass.action(默認)。 – MMMMS 2015-03-03 06:33:35

+0

「我認爲index.jsp是你的默認頁面」是錯誤的。請檢查我更新的問題。 – MMMMS 2015-03-03 06:37:13

+0

我說「承擔」,因爲你以前沒有發佈你的web.xml,但web.xml不需要分析這個問題,我相信 – divine 2015-03-03 07:23:55