java ee - how to obtain the relative path of a resource in a j2ee project -


I have a dynamic web project (or text file) with a successful file I have created a servlet in which I Need to use

My code is as follows:

  Secure zero code (HTTPSvette request), servlet throws excitation, IOException {// string processing = request.getParameter ("Jason") ; If (resource! = Null & amp;! Resources.equals ("")) {// use getResourceAsStream () to use the file properly, InputStream = getServletContext () .getResourceAsStream ("JSON" "); If (is! = Zero) {// resource is present.setContentType ("application / json"); Response.setHeader ("Pagera", "No-Cash"); Response.setDateHeader ("End", 0); Response.setHeader ("cache-control", "no-cache"); Stringwright SW = new stringwriter (); (Int c = is.read (); c! = -1; c = is.read ()) {sw.write (c); } PrintWriter out = response.getWriter (); outside. Print (sw.toString ()); Out.flush (); }}  

}

The problem is that InputStream is a zero value.

How do I get the right relative path I am using jeunes as an eb server.

I have added a resource file to the WebContent directory of a dynamic web project. As a different perspective, I tried to do this:

  Protects Zero doGet (HTTPPervelate Request Request, HTTPSvette Response Response), Servlet Upption throws, IOException {// TODO auto generated method Stub ServletConfig config = getServletConfig (); String reference name = config.getInitParameter ("ApplicationName"); System.out.println ("context name" + reference name); String referencepath = config.getServletContext (). GetRealPath (reference name); System.out.println ("Reference Path" + Reference); // contextPath = contextPath.substring (0, contextPath.indexOf (reference name)); References + = "\\ JSONTX"; Println (contextPath); String processing = request.getParameter ("Jason"); System.out.println ("Hi is 1" + resource); If (resource! = Null & amp; resource.exe ("")) {System.out.println ("hi there"); // Get GetResourceAsStream () to get the file properly. // InputStream = getServletContext () .getResourceAsStream (resource); InputStream = getServletConfig () GetServletContext (). GetResourceAsStream (textText); If (is! = Null) {// resource exists system.out.println ("Hi is 2"); Response.setContentType ("application / json"); Response.setHeader ("Pagera", "No-Cash"); Response.setDateHeader ("End", 0); Response.setHeader ("cache-control", "no-cache"); Stringwright SW = new stringwriter (); (Int c = is.read (); c! = -1; c = is.read ()) {sw.write (c); Println (c); } PrintWriter out = response.getWriter (); outside. Print (sw.toString ()); Println (sw.toString ()); Out.flush (); }}}  

The value of the reference page is now: C: \ JBOSS \ jboss-5.0.1.GA \ server \ default \ tmp \ 4p72206b-uo5r7k-g0vn9pof-1-g0vsh0o9- B7 \ Nationwide.war \ WEB-INF \ rates JSN

But this place does not have a JSN file? It seems that JBOSS is not keeping this file in App.war or it does not deploy ??? Can anyone please help me?

First of all, check national level. Judge to ensure rate If so, try:

  string rootPath = getServletConfig (). GetServletContext (). GetRealPath ("/"); File file = new file (actual path + "web-ihenf / rate jsnttpt"); InputStream = new FileInputStream (file);  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -