java读取本地的html文件并且将其样式原样的显示在浏览器中

java读取本地html文件并且将其样式原样的显示在浏览器中,且不能将其路径显示在地址栏中!求大神解答!就这些币了,全给了!

类似这样


public class ServletClass extends HttpServlet
{
protected void doGet(HttpServletRequest request , HttpServletResponse response)
{
  this.doPost(request , response);
}

protected void doPost(HttpServletRequest request , HttpServletResponse response)
{
  int i = 1;

  try {
   request.setCharacterEncoding("utf-8");
   response.setContentType("text/html;charset=utf-8");
   PrintWriter out = response.getWriter();

   out.println("<html>");
   out.println("<head>");
   out.println("<title></title>");
   out.println(" <meta http-equiv='keywords' content='keyword1,keyword2,keyword3'>");
   out.println("<meta http-equiv='description' content='this is my page'>");
   out.println("<meta http-equiv='content-type' content='text/html; charset=UTF-8'>");
   out.println("<link rel='stylesheet' type='text/css' href='css/index.css'>");
   out.println(" </head>");
   out.println("<body >");


   out.println("</div>");
   out.println(" </body>");
   out.println("</html>");    

  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
}
}

用servlet是没错的,在方法体里面可以写成IO流 然后给上HTML文件的 path路径,然后用流读取文件全部内容输出到想要跳转的页面;如果你知道节点那个东西怎么获取的话,可以直接得到body的内容

是不是这样的呀 http://localhost:端口号/域名

前面那个人说的没有问题,直接用IO读即可,如果是想显示在iframe里面可以用ajax实现。

如果要显示在浏览器中,那么另一个思路就是浏览器addon插件,通过插件来加载html文件,组织成DOM接口,插件调用JS引擎显示页面

还有种方法就是作为静态资源调用就可以了,网页的内容都是在服务器下的虚拟目录,不存在看到路径的问题的。虚拟目录都是在ROOT下;
显示也会是 http://localhost/域名/命名空间/资源这样的结构显示的