首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行index.jsp时无法显示表

运行index.jsp时无法显示表
EN

Stack Overflow用户
提问于 2018-05-22 23:44:16
回答 1查看 67关注 0票数 1

在我的网页应用程序中,欢迎页面需要显示一张桌子。但是它(http://localhost:8080/MyApp )显示"null“,但是如果我添加'ServlentToRead.java‘--我的意思是,http://localhost:8080/MyApp/ServlentToRead --它会显示表。

为什么我不能把这张桌子作为第一页?这是index.jsp

代码语言:javascript
复制
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%
    String table=(String) request.getAttribute("table");

%>
<!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>Mytable</title>

</head>

<body>

<h1>Mytable</h1>

<%= table %>

</body>
</html>

编辑:

代码语言:javascript
复制
<?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"
    version="3.1">
    <display-name>MyApp</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-23 00:10:59

为什么我不能把这张桌子作为第一页?

将您的web.xml更改为:

代码语言:javascript
复制
<?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" version="3.1">
<display-name>MyApp</display-name>
  <welcome-file-list>
    <welcome-file>ServlentToRead</welcome-file>
  </welcome-file-list>
</web-app>

当您访问url时,您现在将看到该表:

代码语言:javascript
复制
http://localhost:8080/MyApp

编辑:对不起,从web.xml中删除正斜杠:

代码语言:javascript
复制
<welcome-file>/ServlentToRead</welcome-file>

看起来是这样的:

代码语言:javascript
复制
<welcome-file>ServlentToRead</welcome-file>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50477922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档