如何從.jsp訪問ServletContext?例如,如何在.jsp中調用getRealPath方法。Java(JSP/Servlet):等同於.jsp中的getServletContext()
這裏有一個Servlet,這工作得很好:
protected void doGet(
HttpServletRequest req,
HttpServletResponse resp
) throws ServletException, IOException {
resp.setContentType("text/html; charset=UTF-8");
final PrintWriter pw = resp.getWriter();
pw.print("<html><body>");
pw.print(getServletContext().getRealPath("text/en"));
pw.print("</body></html>");
pw.flush();
pw.close();
}
現在我正在尋找的線我應該在以下的.jsp做完全一樣的東西插入作爲servlet上面正在做。
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
... // What should I insert here
</body>
</html>
參見http://stackoverflow.com/questions/2964250/jsp-getservletcontext-error – Vadzim 2017-01-25 15:32:41