0

我正在使用 GWT,我想从 servlet 中抛出 html 内容。但是当我调用 servlet 并将内容扔给浏览器时,它会显示一些异常:

GET http://127.0.0.1:8888/com.opt.opt/opt.css 404 (Not Found) 5C1C7AB6A2CE69634F1821FF011F5710.cache.html:1
GET http://127.0.0.1:8888/com.opt.opt/AppOpsClient.css 404 (Not Found) 5C1C7AB6A2CE69634F1821FF011F5710.cache.html:1
GET http://127.0.0.1:8888/com.opt.opt/MessageComponent.css 404 (Not Found) 5C1C7AB6A2CE69634F1821FF011F5710.cache.html:1
GET http://127.0.0.1:8888/com.opt.opt/com.opt.opt/com.opt.opt.nocache.js 404 (Not Found) 5C1C7AB6A2CE69634F1821FF011F5710.cache.html:1

我的 servlet 正在抛出以下内容:

String html = "<!doctype html>"+
             "<html>"+
              "<head>"+
                "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">" +
                "<link type=\"text/css\" rel=\"stylesheet\" href=\"opt.css\">"+
                "<link type=\"text/css\" rel=\"stylesheet\" href=\"AppOpsClient.css\">"+
                "<link type=\"text/css\" rel=\"stylesheet\" href=\"MessageComponent.css\">"+
                "<title>demoopt</title>"+
                "<script type=\"text/javascript\" language=\"javascript\" src=\"com.opt.opt/com.opt.opt.nocache.js\"></script>"+
                 "</head>"+
              "<body>"+
                /*"<iframe src=\"javascript:''\" id=\"__gwt_historyFrame\" tabIndex='-1' style=\"position:absolute;width:0;height:0;border:0\"></iframe>"+
                "<noscript>"+
                  "<div style=\"width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif\">"+
                    "Your web browser must have JavaScript enabled"+
                    "in order for this application to display correctly."+
                  "</div>"+
                "</noscript>"+*/
              "</body>"+
            "</html>";

response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println(html);
            out.close();

它显示了这个异常,因为它附加了模块名,即 com.opt.opt 到 css 文件和缓存文件。我不明白为什么在将内容扔到浏览器时将模块名称附加到缓存文件。在部署模式以及托管 ode 中,它会抛出相同的异常。

任何人都可以建议我任何解决方案。:(

4

1 回答 1

2

将链接设为绝对路径(以 开头HttpServletRequest#getContextPath()

于 2013-04-23T12:57:12.810 回答