本文介绍了运行index.jsp时无法显示表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Web应用程序中,欢迎页面需要显示一个表格.但是,它( http://localhost:8080/MyApp )显示为"null",但是如果我添加'ServlentToRead .java'的意思是, http://localhost:8080/MyApp/ServlentToRead 它显示了表格.
In my web app the welcome page needs to show a table. However it (http://localhost:8080/MyApp ) shows "null" , but if I add 'ServlentToRead.java' I mean, http://localhost:8080/MyApp/ServlentToRead it displays the table.
为什么我不能将表格作为首页?这是index.jsp
Why I can't get the table as first page ? here is the 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>
推荐答案
将您的web.xml更改为此:
change your web.xml to this:
<?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时,您都会看到该表:
You will now see the table whenever you visit the url:
http://localhost:8080/MyApp
编辑:抱歉,请从您的web.xml中删除正斜杠:
sorry, remove the forward slash from in your web.xml:
<welcome-file>/ServlentToRead</welcome-file>
所以看起来像这样:
<welcome-file>ServlentToRead</welcome-file>
这篇关于运行index.jsp时无法显示表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!