Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Ajax call to a Servlet ont returning anything

843841Jan 30 2006 — edited Feb 27 2007
Hello all,
I am trying to make a call to a servlet that will basically read the contents of a text file and returns this to a jsp page through an Ajax call.
Problem I am having is the servlet returns nothing.
Here is a snip of my code:
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        File file = new File("C:/logger/Jan31EventLog.txt");
        FileReader filereader = new FileReader(file);
        BufferedReader reader = new BufferedReader(filereader);
        
        String line = null;
        String strLine = "";
        while((line = reader.readLine()) != null)
        {
          strLine = line;
        }
          response.setContentType("text/plain");
          response.setHeader("Cache-Control", "no-cache");
          response.getWriter().write(strLine);
          out.close();
    }
Then in my jsp I make a servlet call through Ajax like so:
function ajaxRead(){

var file = './Logger'; //Logger is the name of my servlet.
//alert(file);
  var xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }
I get no errors so I am not sure if I wrote the servlet properly. If I hard code the file to read with Ajax it works but I need to use the servlet call.
TIA!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 27 2007
Added on Jan 30 2006
4 comments
341 views