Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File not found error

Status
Not open for further replies.

MarkShark

Programmer
Aug 22, 2001
36
US
I have an error in my script finding a file. The servlet error log says

2001-09-18 09:01:17 - path="" :jsp: init
2001-09-18 09:02:08 - path="" :LoginServlet: init
2001-09-18 09:03:45 - path="" :abcServlet: init
2001-09-18 09:03:52 - path="" :xyzServlet: init
2001-09-18 09:03:55 - path="" :Error: /usr/local/apache/sites/abc.spinweb.net/htdocs/xxx/courses\3M/Introduction/3m_intro.html (No such file or directory)

As you can see a "\" is loaded after "courses" where a "/" should be. the html is loaded exactly where it says with the exception of the backward slash. I can't find where it is being called from, but suspect it lays in the code below. Could anyone help me in this matter, or tell me where else I should look. Thanks.



private String getAUHtml (String path){
path = path.replace ('\\', '/');
String response;
response = &quot;<html>\n&quot; +
&quot;<head>\n&quot; +
&quot;</head>\n&quot; +
&quot;<body>\n&quot; +
&quot;<script language=\&quot;JavaScript\&quot;>\n&quot; +
&quot;document.location = \&quot;/cmi/courses/&quot; + path + &quot;\&quot;\n&quot; +
//&quot;win = window.open ('','displayWindow','menubar=yes,scrollbars=yes,status=yes,width=300,height=300');\n&quot; +
//&quot;window.onload = \&quot;win.close();\&quot;&quot; +
&quot;</script>\n&quot; +
&quot;</body>\n&quot; +
&quot;</html>\n&quot;;
return response;
 
Could you post more of the code, at least the part where path gets set. I am bit confused, I have never recieved this error. I would suggest, in the meantime, start putting printlns throughout the code to check the value of path. Until I see more that may be the best recommendation that I can make. Wushutwist
 
Here is somem more code. I never had this happen either so it has me pulling my hair out. Thanks...

try {
HttpSession session = request.getSession (true);
//can I load the session given the id??
//System.out.println (&quot;Lesson.valid session &quot; + session.getId() + &quot;: &quot; + request.isRequestedSessionIdValid());
response.setContentType (&quot;text/html&quot;);
JDBCHelper dbHelper = new JDBCHelper (_jdbcConnection);

//get student ID
Integer studentID = (Integer) session.getAttribute (&quot;studentID&quot;);
//get course ID
Integer courseID = (Integer) session.getAttribute (&quot;courseID&quot;);
//get lesson ID
String lessonID = request.getParameter (&quot;lessonID&quot;);
if (lessonID == null) {
lessonID = (String) session.getAttribute (&quot;lessonID&quot;);
}

if (studentID == null || courseID == null || lessonID == null) {
//reset session data by re-logging the user
sendProfileError (response.getOutputStream());
return;
}

//store lesson ID in session
session.setAttribute (&quot;lessonID&quot;, lessonID);

String auID = request.getParameter (&quot;auID&quot;);
String mode = request.getParameter (&quot;mode&quot;);
if (mode != null) {
session.setAttribute (&quot;mode&quot;, mode);
}
else {
mode = (String) session.getAttribute (&quot;mode&quot;);
}
if (mode.equalsIgnoreCase (&quot;review&quot;)) {
normalMode = false;
}
else {
normalMode = true;
}

//synchronize access to course hash table
synchronized (_courseHash)
{
//make sure _courseHash is in tact
if (_courseHash == null) {
//try reloading it....
loadCourseData();
if (_courseHash == null) {
//error
response.getOutputStream().close();
throw new IOException (&quot;Corrupt course data&quot;);
}
}
if (! _courseHash.containsKey (courseID.toString())) {
//try reloading it....
loadCourseData();
if (! _courseHash.containsKey (courseID.toString())) {
//error
response.getOutputStream().close();
throw new IOException (&quot;Corrupt course data (course not found)&quot;);
}
}
}

if (auID == null) {
//show course menu
Hashtable hash = (Hashtable) _courseHash.get (courseID.toString());
sendAvailableAUs (hash, studentID.intValue(), courseID.intValue(), lessonID, response.getOutputStream(), response, dbHelper);
return;
}

//if AU has not been attempted, initialize it
Integer auDataID = new Integer (getAUDataID (studentID.intValue(), courseID.intValue(), lessonID, auID, dbHelper));
//if (getAUDataID (studentID.intValue(), courseID.intValue(), lessonID, auID, dbHelper) == -1) {
if (auDataID.intValue() == -1) {
int newID = initializeAUData (studentID.intValue(), courseID.intValue(), lessonID, auID, dbHelper);
dbHelper.addAUToPath (studentID.intValue(), courseID.intValue(), lessonID, auID);
auDataID = new Integer (newID);
}

session.setAttribute (&quot;AUID&quot;, auID);
session.setAttribute (&quot;AUDataID&quot;, auDataID);

sendAU (studentID.intValue(), courseID.intValue(), lessonID, auID, auDataID.intValue(), normalMode, response.getOutputStream(), dbHelper);
}
//to do: detailed messages should be sent to the client depending on which
// exception was thrown. Don't have one try/catch....have one for each situation
catch (Exception e) {
e.printStackTrace();
getServletContext().log(&quot;Error: &quot; + e.getMessage());
}
}

public void destroy()
{
try {
if (_jdbcConnection != null) {
_jdbcConnection.close();
}
}
catch (Exception ignored) {}
}

private int initializeAUData (int studentID, int courseID, String lessonID, String auID, JDBCHelper dbHelper)
{
String sqlQuery = null;
ResultSet results = null;
try {
//get student's name
sqlQuery = &quot;SELECT Full_Name&quot; +
&quot; FROM &quot; + GlobalData.StudentTable +
&quot; WHERE Student_ID = &quot; + studentID;
results = dbHelper.doQuery (sqlQuery);
if (! results.next()) {
//error
return -1;
}
String studentName = results.getString (1);
results.close();

//the lock prevents CMIServlet from reading AU_ID before it's committed
//sqlQuery = &quot;LOCK TABLES &quot; + GlobalData.AUDataTable + &quot; WRITE;&quot;;
//System.out.println (sqlQuery);
//dbHelper.executeUpdate (sqlQuery);

sqlQuery = &quot;Insert Into &quot; + GlobalData.AUDataTable +
&quot;(Course_ID, Lesson_ID, AU_ID, student_id, student_name, lesson_location, credit,&quot; +
&quot; lesson_status, entry, exit, score_raw, score_max, score_min, total_time,&quot; +
&quot; session_time, lesson_mode, suspend_data, launch_data, Evaluation_ID, Objective_ID)&quot; +
&quot; Values (&quot; + courseID + &quot;, '&quot; + lessonID + &quot;', '&quot; + auID + &quot;', &quot; + studentID + &quot;, '&quot; + studentName + &quot;',&quot; +
&quot; 'NA', 'credit',&quot; + &quot; 'not attempted', 'ab-initio', &quot; + &quot;'NA', &quot; + 0 + &quot;, &quot; + 0 + &quot;, &quot; + 0 +
&quot;, '00:00:00.0', '00:00:00.0', &quot; + &quot; 'normal'&quot; + &quot;, 'NA', &quot; + &quot;'NA', &quot; + 0 + &quot;, &quot; + 0 + &quot;);&quot;;
dbHelper.executeUpdate (sqlQuery);

return getAUDataID (studentID, courseID, lessonID,auID, dbHelper);
//sqlQuery = &quot;UNLOCK TABLES;&quot;;
//System.out.println (sqlQuery);
//dbHelper.executeUpdate (sqlQuery);
}
catch (Exception e) {
e.printStackTrace();
getServletContext().log(&quot;Error: &quot; + e.getMessage());
}
return -1;
}

private int getAUDataID (int studentID, int courseID, String lessonID, String auID, JDBCHelper dbHelper)
throws SQLException
{
String sqlQuery = &quot;SELECT AUData_ID, lesson_status, lesson_mode, exit&quot; +
&quot; FROM &quot; + GlobalData.AUDataTable +
&quot; WHERE student_id = &quot; + studentID +
&quot; AND Course_ID = &quot; + courseID +
&quot; AND Lesson_ID = &quot; + &quot;'&quot; + lessonID + &quot;'&quot; +
&quot; AND AU_ID = '&quot; + auID + &quot;';&quot;;
ResultSet results = dbHelper.doQuery (sqlQuery);
if (results.next()) {
return results.getInt (&quot;AUData_ID&quot;);
}
return -1;
}

private void sendAU (int studentID, int courseID, String lessonID, String auID, int auDataID, boolean normalMode, ServletOutputStream htmlOut, JDBCHelper dbHelper)
throws IOException, ClassNotFoundException
{
Hashtable hash = null;
synchronized (_courseHash)
{
hash = (Hashtable) _courseHash.get (String.valueOf (courseID));
if (hash == null) {
loadCourseData();
hash = (Hashtable) _courseHash.get (String.valueOf (courseID));
if (hash == null) {
throw new IOException (&quot;Corrupt course data (course not found)&quot;);
}
}
}
AU au = (AU) hash.get (auID);

try {
if (! normalMode) {
dbHelper.setReviewMode (auDataID);
}
String courseFileName = getFileName (String.valueOf (courseID), dbHelper);
File file = new File (courseFileName);
//create absolute path to file so we can resolve relative URLs
String newFileName = file.getParent() + &quot;\\&quot; + au.getLaunchParams();
BufferedReader buf = new BufferedReader (new FileReader (newFileName));
PrintWriter htmlWriter = new PrintWriter (htmlOut);
String temp;
htmlWriter.write (getAUHtml (au.getLaunchParams()));
htmlWriter.flush();
htmlWriter.close();
}
catch (Exception e) {
e.printStackTrace();
getServletContext().log(&quot;Error: &quot; + e.getMessage());
}
}

private String getAUHtml (String path){
path = path.replace ('\\', '/');
String response;
response = &quot;<html>\n&quot; +
&quot;<head>\n&quot; +
&quot;</head>\n&quot; +
&quot;<body>\n&quot; +
&quot;<script language=\&quot;JavaScript\&quot;>\n&quot; +
&quot;document.location = \&quot;/cmi/courses/&quot; + path + &quot;\&quot;\n&quot; +
//&quot;win = window.open ('','displayWindow','menubar=yes,scrollbars=yes,status=yes,width=300,height=300');\n&quot; +
//&quot;window.onload = \&quot;win.close();\&quot;&quot; +
&quot;</script>\n&quot; +
&quot;</body>\n&quot; +
&quot;</html>\n&quot;;
return response;
}
 
When is the error occuring? Compile-time? Deploy-time? Runtime?

Is the HTML page getting displayed or is it failing before that point? If you are getting a page (even a blank one) post the resulting HTML.

Also, what is your Server setup? Apache forwarding to Tomcat? It is so frustrating to troubleshoot problems like these over a forum.

Last question (I promise), is this Servlet publically accessible? If so, what is the url? Wushutwist
 
The error is happening at runtime. When the link is selected, a blank page comes up. Below is the source code for the blank page. My server setup is Apache forwarding to Tomcat. If you e-mail me I'll give you the url for the site. My e-mail is mkain@tesco-inc.com



<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML><HEAD><TITLE>CMI</TITLE>
<META http-equiv=Content-Type content=&quot;text/html; charset=windows-1252&quot;>
<SCRIPT language=JavaScript>
function hideAppletFrame (content) {
frames[0].document.applets[0].stop();
document.open();
document.write (&quot;<html>\n&quot; +
&quot;<head>\n&quot; +
&quot;<title>CMI</title>\n&quot; +
&quot;</head>\n&quot; +
&quot;<frameset cols=\&quot;30%,*\&quot;>\n&quot; +
&quot;<frame>\n&quot; +
&quot;<frame>\n&quot; +
&quot;</frameset>\n&quot; +
&quot;</html>&quot;);
document.close();
frames[1].document.write (content);
frames[0].location = &quot;cmi/LoginFrame.html&quot;;
frames[0].hideForm();
}

function setStatus (message) {
window.status = message;
return true;
}

function restart() {
window.location = &quot;/cmi/CMI.html&quot;;
}

function loadCMIAPIFrame() {
var frame1Location;
if (navigator.appName.indexOf (&quot;Microsoft&quot;) != -1) {
//var temp = frames[1].document.location.href;
//frame1Location = temp.substring (temp.indexOf (&quot;/servlet&quot;));
frames[0].document.location = &quot;/cmi/CMIAPIFrame.html&quot;;
return true;
}
else {
frame1Location = frames[1].location;
}
document.open();
document.write (&quot;<html>\n&quot; +
&quot;<head>\n&quot; +
&quot;<title>CMI</title>\n&quot;);
document.write (&quot;<scr&quot; + &quot;ipt language=\&quot;JavaScript\&quot;>\n&quot; +
&quot;function setStatus (message) {\n&quot; +
&quot; window.status = message;\n&quot; +
&quot; return true;\n&quot; +
&quot;}\n\n&quot;);
document.write (&quot;function restart() {\n&quot; +
&quot; window.location = \&quot;/cmi/CMI.html\&quot;;\n&quot; +
&quot; return true;\n&quot; +
&quot;}\n&quot;);
document.write (&quot;function loadCMIAPIFrame() {\n&quot; +
&quot; return false;\n&quot; +
&quot;}\n&quot; +
&quot;</scr&quot; + &quot;ipt>\n&quot;);
document.write (&quot;</head>\n&quot; +
&quot;<frameset cols=\&quot;0,*\&quot;>\n&quot; +
&quot;<frame src=\&quot;/cmi/CMIAPIFrame.html\&quot;>\n&quot; +
&quot;<frame src=\&quot;&quot; + frame1Location + &quot;\&quot;>\n&quot; +
&quot;</frameset>\n&quot; +
&quot;</html>&quot;);
document.close();
return true;
}
</SCRIPT>
</HEAD><FRAMESET cols=20%,*><FRAME src=&quot;/cmi/LoginFrame.html&quot;><FRAME
src=&quot;/cmi/LMSIntro.html&quot;></FRAMESET></HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top