Note that there are some explanatory texts on larger screens.

plurals
  1. POJava servlets, write data from text file to web page
    text
    copied!<p>I have this servlet code in java:</p> <pre><code>package servlets; import java.io.*; import java.util.*; import javax.servlet.*; import java.net.*; public class Servlet1 extends GenericServlet{ private ServletConfig sc; public void init(ServletConfig conf) throws ServletException{ super.init(conf); sc = conf; } public void read_file(){ String filename = "/web/WEB-INF/Data.txt"; BufferedReader br = new BufferedReader(new FileReader(filename)); // Why this doesn't work ? } public void service(ServletRequest req, ServletResponse resp) throws ServletException,IOException{ resp.setContentType("text/html; charset=windows-1251"); PrintWriter pw = resp.getWriter(); pw.println("&lt;html&gt;&lt;head&gt;"); pw.println("&lt;title&gt;sdasdasda&lt;/title&gt;"); pw.println("&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Servlet information&lt;/h2&gt;"); pw.println("Servlet name - "+sc.getServletName()+ "&lt;br&gt;"); pw.println("Servlet parametrs: &lt;br&gt;"); //pw.println(read_file()); Enumeration names = sc.getInitParameterNames(); while(names.hasMoreElements()){ String name = (String)names.nextElement(); pw.print(name + ": "); pw.println(sc.getInitParameter(name)+"&lt;br&gt;"); } pw.println("&lt;/body&gt;&lt;/html&gt;"); pw.flush(); pw.close(); } public void destroy(){ sc = null; } } </code></pre> <p>And this <code>BufferedReader br = new BufferedReader(new FileReader(filename));</code> always shows that there is no suck file, but I put it in ProjectName/web/Web-INF/ folder. How do i read from this file, or get the right path to it ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload