sourcecodeservlet.java

来自「一个使用struts+hibernate+spring开发的完的网站源代码。」· Java 代码 · 共 46 行

JAVA
46
字号
package org.apache.myfaces.examples.servlet;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;public class SourceCodeServlet extends HttpServlet {    public void doGet(HttpServletRequest req, HttpServletResponse res)        throws IOException, ServletException    {        String webPage = req.getServletPath();                // remove the '*.source' suffix that maps to this servlet        int chopPoint = webPage.indexOf(".source");                webPage = webPage.substring(0, chopPoint - 1);        webPage += "p"; // replace jsf with jsp                // get the actual file location of the requested resource        String realPath = getServletConfig().getServletContext().getRealPath(webPage);        System.out.println("realPath: " + realPath);        // output an HTML page        res.setContentType("text/plain");        // print some html        ServletOutputStream out = res.getOutputStream();        // print the file        InputStream in = null;        try         {            in = new BufferedInputStream(new FileInputStream(realPath));            int ch;            while ((ch = in.read()) !=-1)             {                out.print((char)ch);            }        }        finally {            if (in != null) in.close();  // very important        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?