概述
servlet中输出html页面,为何js,css都失效了?
servlet doget方法:
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
resp.setContentType("text/html");
ContentHtml contenHtml = new HtmlCreater.InitHtmlContent();
PrintWriter w = resp.getWriter();
w.println(contentHtml.getHtmlpage()); //输出a.html页面
}
a.html 部分:
容器为 tomcat, 项目名为abc;
单独输出a.html 页面没有任何问题;
但通过 servlet 输出a.html 时,页面中引入的 js,css文件全都不能识别(js 文件内容没有问题),都指向了a.html页面.
运行时报如下错误:
Uncaught SyntaxError: Unexpected token < jquery.serialize-object.min.js:1
Uncaught SyntaxError: Unexpected token < jquery.1.11.1.min.js:1
Resource interpreted as Stylesheet but transferred with MIME type text/html: “http://localhost:8080/abc/css/bootstrap/bootstrap.min.css”.
最后
以上就是懵懂火车为你收集整理的处理在servlet中无法正常显示html的代码解决方案的全部内容,希望文章能够帮你解决处理在servlet中无法正常显示html的代码解决方案所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复