2013-04-25 247 views
0

我知道有人已經問過這個問題,但我沒有得到我想要的答案。所以我試圖運行使用Tomcat JSP頁面,但我不斷收到以下錯誤信息:Eclipse-HTTP狀態404

HTTP Status 404 - /LoginWeather/ 

type Status report 

message /LoginWeather/ 

description The requested resource is not available. 

的Apache Tomcat/7.0.39

服務器配置正確,本地主機: 8080功能正常。這是我的web.xml和我的.jsp文件內容: web.xml中:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>LoginWeather</display-name> 
    <welcome-file-list> 
    <welcome-file>login.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> 

的login.jsp:``

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ 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=ISO-8859-1"> 
<title>Welcome</title> 
</head> 
<body> 
<s:form> 
    <s:textfield label="Username" key="userName"/> 
    <s:password label="Password" key="password"/> 
    <s:submit/> 
</s:form> 
</body> 
</html> 
+0

試一下'http:// localhost:8080/LoginWeather/login.jsp' – 2013-04-25 17:04:00

+0

當你只運行JSP時,那麼這個url就是你給的那個,我已經試過了。同樣的錯誤出現。 – 2013-04-25 17:44:09

+0

我不知道你把JSP放在哪裏,404意味着你的JSP不存在。 – 2013-04-25 20:33:49

回答

0

嘗試與添加以下內容index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Refresh" content="0;URL=login.action"/> 
<title>Insert title here</title> 
</head> 
<body> 

然後你web.xml看起來是:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>LoginWeather</display-name> 
    <welcome-file-list> 
    <welcome-file>index.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> 

加載後index.jsp會自動重定向到login.jsp

您也可以嘗試在您的瀏覽器中輸入http://localhost:8080/LoginWeather/login.action來顯示login.jsp

+0

您的歡迎頁面的名稱無關緊要。它也應該運行,如果我右鍵單擊我的login.jsp代碼並選擇運行 - >在服務器上運行... – 2013-04-26 06:47:49

+0

但是,如何訪問您的jsp頁面是非常重要的。在struts 2中,輸入login.jsp將不起作用,直到你不會使用動作映射--login.action。所以我提供了自動觸發login.action – 2013-04-26 19:45:57