code_junkie

Accessing Tomcat Context Path from Servlet

Nov 10th, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. public void init(final ServletConfig config) {
  2. final String context = config.getServletContext().getRealPath("/");
  3. ...
  4. }
  5.  
  6. ...
  7.  
  8. public class MyServlet extends HttpServlet {
  9.  
  10. public void init(final ServletConfig config) {
  11. final String context = config.getServletContext();
  12. ...
  13. }
  14.  
  15. ...
  16. }
  17.  
  18. File file = new File(getServletContext().getResource("/js/file.js").getFile());
  19.  
  20. InputStream input = getServletContext().getResourceAsStream("/js/file.js");
Add Comment
Please, Sign In to add comment