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!