【发布时间】:2011-02-23 07:29:57
【问题描述】:
我应该如何从 .jsp 访问 ServletContext?例如,如何从 .jsp 中调用 getRealPath 方法。
这是一个 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>
【问题讨论】: