2011-08-21 85 views
0

我运行的Java宠物商店例子,这是我的“的index.jsp”文件的顶部:为什么Firefox会将我的JSP网页文件作为原始源代码打开并且不显示实际页面?

<%-- Copyright 2006 Sun Microsystems, Inc. All rights reserved. You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at: http://developer.sun.com/berkeley_license.html 
$Id: index.jsp,v 1.20 2007-03-16 20:18:59 basler Exp $ --%> 

<%@page contentType="text/html"%> 
<%@page pageEncoding="UTF-8"%> 
<%@page import="java.util.*, com.sun.javaee.blueprints.petstore.model.CatalogFacade, com.sun.javaee.blueprints.petstore.model.Tag"%> 

<% 
try { 
    CatalogFacade cf = (CatalogFacade)config.getServletContext().getAttribute("CatalogFacade"); 
    List<Tag> tags=cf.getTagsInChunk(0, 12); 
    // since top 20 come from database or desending refCount order, need to reorder by tag name 
    Collections.sort(tags, new Comparator() { 
     public int compare(Object one, Object two) { 
      int cc=((Tag)two).getTag().compareTo(((Tag)one).getTag()); 
      return (cc < 0 ? 1 : cc > 0 ? -1 : 0); 
     } 
    });  
%> 

<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > 
     <title>Java Pet Store Reference Application</title> 
     <link type="text/css" rel="stylesheet" href="./tag.css"/> 
    </head> 
    <body> 

....

+1

你看到了哪些原始的源代码? – SLaks

+0

我在这里发布的代码 - 当我点击index.jsp时,我得到了这个。我确实尝试将其重命名为“index.html”,但显示的页面不正确(看起来像一个没有图形/功能的框架)。 – Coffee

+1

您使用的服务器是什么? – fvu

回答

2

这不是对您的问题的直接回答,但我会尝试显示呈现JSP的内容。遵循该路径并分析domains/domain1/server.log(如果您的安装使用名为domain1的默认域),可能会提示您有什么问题。

通常在GF2中,在域的config目录中有一个名为default-web.xml的文件。

它包含这些内容摘要:

<servlet> 
    <servlet-name>jsp</servlet-name> 
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> 
    <init-param> 
     <param-name>xpoweredBy</param-name> 
     <param-value>true</param-value> 
    </init-param> 
    <load-on-startup>3</load-on-startup> 
    </servlet> 

上面的代码配置JSP支持 - 当然,如果它不能找到servlet代码它会失败,但应该在server.log中被记录下来。

之后,下面的代码片段确保调用上面的servlet来管理jsp的 - 一个“经典”jsp的映射和一个“xml语法”jsps的映射。现在

<servlet-mapping> 
    <servlet-name>jsp</servlet-name> 
    <url-pattern>*.jspx</url-pattern> 
    </servlet-mapping> 


    <!-- ================ Built In Servlet Mappings ========================= --> 


    <!-- The mapping for the JSP servlet --> 
    <servlet-mapping> 
    <servlet-name>jsp</servlet-name> 
    <url-pattern>*.jsp</url-pattern> 
    </servlet-mapping> 

,如果出于某种原因,这些片段中缺少默认-web.xml中,JSP的支持将是无效的,你会得到像你描述的,因为该文件将由拿起一个有影响默认的servlet,并将作为一个静态资源来处理。

+0

这是非常有用的,我现在正在阅读日志。非常感谢你! – Coffee

6

也许服务器不为服务JSP适当配置页面,或者mime/type可能没有为JSP页面正确配置。

+1

他可能服务的网站是mime类型''text/plain“'而不是'”text/html“' – Raynos

+2

@Raynos no - 我怀疑服务器有一个配置问题,导致它无法看到它应该编译JSP,然后运行编译后的代码,这就像mimetypes之类的东西来玩之前。 – fvu

0

这可能是相当古老的,但我也遇到过这个问题,它与使用浏览器显示一个JSP页面有关(该页面目前不由服务器托管或管理,换句话说,服务器已关闭)。

所以这是发生了什么图形的解释:

有装载与Firefox只显示原始代码/计划文本 img1

有相同的页面正确加载页面,用于验证目的的源代码是可见的,注意到两个页面具有相同的代码 img2

发生此问题,因为这两个网页有不同的文件enconding,一个是ANSI(谁通常显示的)和行吟诗人r是UTF-8(显示原始代码的人)。所以要解决这个问题,我们需要:

  1. 打开有问题的网页用记事本
  2. 文件>另存为...
  3. 选择ANSI编码组合框
  4. 选择所有文件在保存类型组合框
  5. 打开的页面再次验证正确

img3

页面显示正确 img4

显示
相关问题