日期:2014-05-18 浏览次数:20757 次
采用Servlet即可: 先应该有一个index.html //IndexServlet.java package com.yuce.servletapp; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class IndexServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter out = resp.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"); out.println("<title>Insert title here</title>"); out.println("</head>"); out.println("<body>"); if(getServletConfig().getInitParameter("newNewpath")!= null && getServletConfig().getInitParameter("newNewName")!= null){ out.println("<a href=" + getServletConfig().getInitParameter("newNewpath")+">"); out.println(getServletConfig().getInitParameter("newNewName")); out.println("<a>"); } out.println("</body>"); out.println("</html>"); out.flush(); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } } //newReportServlet.java package com.yuce.servletapp; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class newReportServlet extends HttpServlet { private FileReader fr; private BufferedReader br; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { fr = new FileReader(getServletConfig().getInitParameter("filename")); br = new BufferedReader(fr); PrintWriter out = resp.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<meta http-equiv=\"Content-Type\""+ "content=\"text/html; charset=UTF-8\">"); out.println("<title>Insert title here</title>"); out.println("</head>"); out.println("<body>"); out.println("<h4 align=\"center\"> " + getServletConfig().getInitParameter("title") + "</h4>"); out.println("<hr>"); String s = null; StringBuffer sb = new StringBuffer(); while((s = br.readLine())!= null){ sb.append(s); sb.append("\n"); } out.println("<pre>" + sb.toString() + "</pre>"); out.printl