2016-06-30 3 views
-1

Я кодирую страницу jsp со структурой struts. Во время работы я получаю ошибку 404.Ошибка 404 при запуске jsp-страницы в Eclipse

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>Insert title here</title> 
</head> 
<body> 
<s:form action="login" method="post"> 
<s:textfield name="id" label="Employee Id"></s:textfield> 
<s:textfield name="name" label="Employee Name"></s:textfield> 
<s:submit value="submit"></s:submit> 
</s:form> 
</body> 
</html> 

LoginAction.java

package Login; 

public class LoginAction { 
    private int id; 
    private String name; 

    public int getId() { 
     return id; 
    } 

    public String getName() { 
    return name; 
    } 

    public String execute(){ 
     return "success"; 
} 
} 

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"> 
<struts> 
<constant name="struts.devMode" value="true" /> 
    <package name="Login" extends="struts-default" namespace="/" > 
    <default-action-ref name="upload" /> 


     <action name="login" class="Login.LoginAction" method="execute"> 
<result name="success">products.jsp</result> 
</action> 


    </package> 
</struts> 

web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> 
    <display-name>Product</display-name> 



    <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> 



    <welcome-file-list> 
    <welcome-file>Login.jsp</welcome-file> 
    </welcome-file-list> 
    </web-app> 

products.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>product images</title> 

</head> 
<body> 
<a href="productdetails.jsp"><img src="images/bp.jpg" class="tooltip" title="BP monitor" id="BP monitor"> </a> 
<a href="productdetails.jsp"><img src="images/sethescope.jpg" class="tooltip" title="sethescope" id="sethescope"></a> 


    </body> 
</html> 

Проект исследователь: enter image description here Результат: enter image description here

+0

Приветственная страница недоступна. –

+0

Можете ли вы просто прояснить? Я приветствую страницу Login.jsp..why, это недоступно? –

+0

Это ошибка: –

ответ

0

Ваш URL должен быть http://localhost:8080/webapp/products Ваши отсутствует WebApp части, которая является вашим именем файла WAR.

+0

http: // localhost: 8080/hello/- это был мой предыдущий проект, он отлично работает. Почему новый не работает? –

+0

Посмотрите ближе к названию проекта. –

+0

Название проекта: Продукты –

0

Raj, В URL-адресе вам необходимо использовать правильный контекстный контекст с учетом регистра (имя файла войны по умолчанию). Если контекст «Продукты» попробовать локальный: 8080/Продукты

Также проверьте Tomcat DOC на http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Introduction

Смежные вопросы