Web.xml警告“对Web内容中不存在的主文件名引用”
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Web.xml警告“对Web内容中不存在的主文件名引用”相关的知识,希望对你有一定的参考价值。
题:
- 我想在web.xml中将servlet“main”设置为欢迎文件,但它显示警告“web内容中不存在的主文件名引用”
- 浏览器无法访问CSS文件,但可以访问属于同一父目录“assests”的图像
- 我想知道这两个问题是否相关以及如何解决它们
我已经引用的内容:
- how-to-include-external-css-file-in-jsp
- 类似的SO问题:qazxsw poi,qazxsw poi,qazxsw poi
结果:
veb.hml
3
main Servlet.Java
http://localhost:8080/SampleApplication
MainView.jsp
http://localhost:8080/SampleApplication/main
目录结构
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>SampleApplication</display-name>
<welcome-file-list>
<welcome-file>main</welcome-file>
</welcome-file-list>
</web-app>
谢谢!
您应该在@WebServlet(name = "main", urlPatterns = { "/main" })
public class MainServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public MainServlet() {
super();
}
/**
* Forwards to the main page.
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher dispatcher
= this.getServletContext().getRequestDispatcher("/WEB-INF/views/MainView.jsp");
dispatcher.forward(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Additional Logic
}
元素中定义欢迎文件列表。所以请尝试将其更改为<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ship Short Dated Products</title>
<!-- ---------------------- BOOTSTRAP AND CUSTOM STYLESHEETS ----------------------- -->
<link rel="stylesheet" type="text/css"
href="<c:url value="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500" />">
<link rel="stylesheet" type="text/css"
href="<c:url value="/assets/bootstrap-3.3.7-dist/css/bootstrap.min.css" />">
<link rel="stylesheet" type="text/css"
href="<c:url value="/assets/font-awesome/css/font-awesome.min.css" />">
<link rel="stylesheet" type="text/css"
href="<c:url value="/assets/css/form-elements.css" />">
<link rel="stylesheet" type="text/css"
href="<c:url value="/assets/css/main-layout.css" />">
<!--
--------------------------- JQUERY AND BOOTSTRAP PLUGINS -------------------------------
--------------------------- Please maintain the order for libs -------------------------
-->
<script
src="<c:url value="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" />"></script>
<script
src="<c:url value="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" />"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- -------------------------------- IMAGE CONTENT -------------------------------- -->
<img class="img-responsive" src="assests/images/HMSGradient.jpg">
<!-- IMAGE CONTENT End -->
</body>
</html>
并将jsp文件移动到。此外,您不需要<welcome-file>
。
以上是关于Web.xml警告“对Web内容中不存在的主文件名引用”的主要内容,如果未能解决你的问题,请参考以下文章
GWT RPC 警告:servlet 有映射,但 web.xml 没有对应的映射
log4j:警告找不到记录器的附加程序(运行 jar 文件,而不是 Web 应用程序)[重复]