java - 运行index.jsp时无法显示表格

标签 java jsp web-applications

在我的网络应用程序中,欢迎页面需要显示一个表格。然而它( http://localhost:8080/MyApp )显示 "null",但如果我添加 'ServlentToRead.java' 我的意思是, http://localhost:8080/MyApp/ServlentToRead它显示表格。

为什么我无法将表格设为首页?这是index.jsp

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

编辑:

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

最佳答案

Why I can't get the table as first page ?

将您的 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" version="3.1">
<display-name>MyApp</display-name>
  <welcome-file-list>
    <welcome-file>ServlentToRead</welcome-file>
  </welcome-file-list>
</web-app>

现在,每当您访问该网址时,您都会看到该表格:

http://localhost:8080/MyApp

编辑:抱歉,请从 web.xml 中删除正斜杠:

<welcome-file>/ServlentToRead</welcome-file>

所以它看起来像这样:

<welcome-file>ServlentToRead</welcome-file>

关于java - 运行index.jsp时无法显示表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50477922/

相关文章:

Java Web 项目与 Jsp 和 Servlet 的连接

java - 在没有字段绑定(bind)的情况下使用表单错误?

java - 将 ArrayList 从 servlet 传递到 JSP

html - 使用 CSS 使工具栏位于顶部

web-applications - SproutCore新手困惑

java - 如何将 ORC BytesColumnVector 值设置为 NULL?

java - 如何将 Netbeans Java 项目和 MySql 中的数据库导出到一起以在不同机器上工作?

java - 如何修复这个 ' Using type org.apache.zookeeper.KeeperException.NoNodeException from an indirect dependency '?

java - 我需要了解 Spring Roo 的 AspectJ 和注释吗?

mysql - 这是否足够,或者我是否有竞争条件?