【问题标题】:404 error while running jsp page in Eclipse在 Eclipse 中运行 jsp 页面时出现 404 错误
【发布时间】:2016-11-02 08:33:17
【问题描述】:

我正在用struts 框架编写一个jsp 页面。运行时出现 404 错误。

登录.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>

项目浏览器: 结果:

【问题讨论】:

  • 您的欢迎页面无法访问。
  • 你能说清楚吗?我的欢迎页面是Login.jsp..为什么无法访问?
  • 这是错误:
  • 警告:找不到指定操作的配置:命名空间中的“产品”:“”。表单动作默认为“动作”属性的文字值。

标签: xml eclipse jsp struts2


【解决方案1】:

您的网址应为http://localhost:8080/webapp/products 您缺少 webapp 部分,这是您的战争文件名。

【讨论】:

  • localhost:8080/hello/-这是我早期的项目,它工作正常。那么为什么新的不能工作?
  • 仔细查看项目名称。
  • 项目名称是 Products
  • 有人请帮帮我
  • 您是否进行了干净的构建并将更新的项目战争部署到 tomcat 中?
【解决方案2】:

拉吉, 您需要在 URL 中使用正确的区分大小写的上下文路径(默认为 war 文件名)。如果您的上下文是“产品”,请尝试 localhost:8080/Products

还可以通过http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Introduction查看 Tomcat 文档

【讨论】:

    猜你喜欢
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 2014-01-13
    • 2016-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多