【问题标题】:struts2 on tomcat project shows blank page, using Fiddler shows 404 errortomcat项目上的struts2显示空白页,使用Fiddler显示404错误
【发布时间】:2013-11-28 04:20:41
【问题描述】:

我的项目使用的是 Tomcat 7.0。

文件结构为:

项目

-src

--项目包

----LogInActon.java

--struts.xml

-网页内容

--Web-INF

----库

------...参考罐子

----Web.xml

--index.jsp

--LogInSuccess.jsp

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="homeLogin" extends="struts-default">

      <action name="logIn" 
            class="com.myApp.system.main.actions.LogInAction" 
            method="execute">
            <result name="success">/logInSuccess.jsp</result>
            <result name="fail">/index.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://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>Welcome</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(默认主页)是:

<%@ 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>
<title>Welcome!</title>
</head>
<body>
   <h1>Log in:</h1>
   <form action="logIn">
      <label for="name">Please enter your name  </label>
      <!--<s:textfield name="username" key="label.name1"/><br/>-->
      <s:textfield name="username"/><br/><br/>
      <label for="pw">Please enter your password    </label>
      <s:password name="pw"/><br/><br/>
      <s:submit value="Log In" align="left"/>
   </form>
</body>
</html>

项目在本地主机上成功构建,没有错误,完全按预期工作;但是,当我们部署到在线服务器时,它会显示一个空白页面。使用 Fiddler 我看到请求标头是:

GET /home HTTP/1.1
Host: dev-dev1.wherego.ca
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0

响应头是:

HTTP/1.1 404 Not Found
Date: Thu, 28 Nov 2013 02:50:15 GMT
Server: Apache-Coyote/1.1
Content-Length: 0
Connection: close
Content-Type: text/plain; charset=UTF-8

调试有什么线索吗?

【问题讨论】:

  • 这是不存在资源的 404。您可以验证您尝试访问的 URL 吗?我最好的猜测是 URL 中有一些混淆。您在 localhost 上点击了哪个 URL,您在服务器上尝试了哪个 URL?
  • 你在使用struts2的config-browser插件吗?可能有用。 struts.apache.org/release/2.3.x/docs/config-browser-plugin.html
  • @SaifAsif in localhost 我点击了 localhost:8080/home ,在服务器上是 xxx.com/home,返回不同的结果
  • tomcat 是否在您服务器上的端口80 上运行?默认情况下,tomcat 设置为侦听端口8080。尝试将网址更改为xxx.com:8080/home
  • @SaifAsif 嗯,我没有配置它。使用xxx.com:8080/home时,服务会超时;顺便说一句,我不知道 aws elastic beanstalk 是否会将他们的 tomcat 服务器配置为端口 80 ..

标签: java jsp jakarta-ee tomcat struts2


【解决方案1】:

根据您的评论,您正面临java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0

当您在与预期用途不同的 JRE 版本上运行应用程序时会遇到此异常。简而言之,这只是一个版本不匹配的问题。

版本号51.0 显示您的特定类文件与哪个JRE 版本兼容。 51.0 表示 JRE 7。与本地主机相比,您在线服务器上运行的 JRE 很可能是不同版本。

要解决此问题,请确保您在其编译到的同一主要 JRE 版本上启动应用程序。您必须在导致问题的在线服务器上安装了 JRE6。

要检查 JRE 的版本,只需触发命令

java -version

在控制台上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-13
    • 2021-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 2017-07-16
    相关资源
    最近更新 更多