2013-06-03 88 views
-1

我是struts和jsp的新手。 目前我被困在上述錯誤,它從最後兩個星期嚴重搞砸了我,不知道我做錯了什麼。 這裏就是我試圖做的事:Struts錯誤:沒有爲命名空間/和動作名稱映射的操作***

temp.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<!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=ISO-8859-1"> 
<title>Sample Page</title> 
</head> 

<body> 
Hello World 
<br/> 

<A href="myAction.action"><font face="arial" color="black" size=2>Run</font></A> 
</body> 
</html> 

在這個頁面中,我有HREF鏈接「運行」,當我點擊這個鏈接,它會調用我的行動並最終調用我的測試.jsp頁面。

test.jsp的

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<!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=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
!!!! Hello !!!! 
</body> 
</html> 

struts.xml的

<?xml version="1.0" encoding="UTF-8"?> 
<struts> 
<constant name="struts.devMode" value="true" /> 
<package name="TestWeb" extends="struts-default" namespace="/"> 
    <action name="myAction"> 
     <result>/test.jsp</result></action></package> 
</struts> 

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
    <display-name>TestWeb</display-name> 
    <welcome-file-list> 
     <welcome-file>index.html</welcome-file> 
     <welcome-file>index.htm</welcome-file> 
     <welcome-file>index.jsp</welcome-file> 
     <welcome-file>default.html</welcome-file> 
     <welcome-file>default.htm</welcome-file> 
     <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 
    <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> 
</web-app> 

朋友,請幫助我。

+0

向我們展示struts.xml。和你正在打的網址。在問題中包含更多細節。 –

+1

使用** code **按鈕('{}'one)並請...縮進您的html:/ –

+0

您的Struts 2配置文件格式錯誤。您正在使用棄用的過濾器。你是否部署到根上下文?如果不是,則應在URL中包含應用上下文。當框架附帶示例時,兩個星期才能獲得一個可用的應用程序? –

回答

1

嘗試

<package name="default" extends="struts-default" namespace="/"> 
      <action name="myAction" 
     class="com.action.MyAction" > 
     <result name="success">result.jsp</result> 
    </action> 

</package> 

在JSP

<a href="<s:url action="myAction"/>">click here</a> 

OR(@湯姆的建議)

<s:a action="myAction" >click here</s:a> 

同時,確保struts.xml配置文件是在classpath

+0

它存在於struts.xml文件中。 – shofee

+0

你寫的是什麼作品,但我發現下面的語法更好:'點擊這裏' – tom

+0

@tom:謝謝你的建議。我會更新,以回答 –

-1

請確保在您的web.xml和temp.jsp中添加ActionServlet,將href更改爲myaction。

+0

請你詳細說明,因爲我是新手,我不明白你在說什麼。 – shofee

+3

Struts 2不使用動作servlet,而是使用過濾器。 –

相關問題