[code]public class CreateXmlAction extends HttpServlet {
private ServletConfig config;
public void init(ServletConfig config) throws ServletException {
this.config = config;
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String filePath = config.getServletContext().getRealPath("/");
}
}[/code]
或者直接在继承了HttpServlet的Servlet中写:
[code]String filePath=this.getServletConfig().getServletContext().getRealPath("/");[/code]
private ServletConfig config;
public void init(ServletConfig config) throws ServletException {
this.config = config;
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String filePath = config.getServletContext().getRealPath("/");
}
}[/code]
或者直接在继承了HttpServlet的Servlet中写:
[code]String filePath=this.getServletConfig().getServletContext().getRealPath("/");[/code]