Win a copy of Spring Boot in Practice this week in the Spring forum!

Peter W Smith

Greenhorn
+ Follow
since Aug 28, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Peter W Smith

I thought I know well about session in specific and web application in general, but I got weird error with my app running on JRun 4. So please answer my question below.
Web Application Scenerio:
There are five pages in the simplified application: home.htm, account.jsp, account_detail.jsp, login.htm, logout.jsp.
A User first requests the home.htm page which contains a link to account.jsp. In web.xml, account.jsp and
account_detail.jsp are configured to be protected while home.htm is not. So when the user clicks on the link to
account.jsp on the home.htm page, Jrun serves the standard login.htm page for the user to enter id and password. A
successful login leads the user to the account.jsp.
Account.jsp is coded with "session=true", and it creates serializable objects and stores them in "session". The links
on it allows the user to natigate to account_detail.jsp. Account_detail.jsp is coded with "session=true", and it
accesses the previously-created "session attributes/objects". In addition, it contains the logout button which links
to logout.jsp page. On the logout.jsp page, "session.invalidate()" is called.
One usage scenerio:
(1) user requests home.htm
(2) user clicks on the link to account.jsp in home.htm
(3) Jrun sends login.htm to user, and user submits corrent id/password
(4) Jrun authentidates/authorizes the user, and executes/sends back account.jsp
(5) user clicks the link to navigate to account_detail.jsp
(6) user clicks on logout button on account_detail.jsp
(7) "session.invalidate()" is called in logout.jsp before this page is sent back to user.
(8) the link to home.htm on logout.jsp page allows the user to navigate back to home.htm
(9) from the home.htm, the next login/access/logout sequence starts.
(10) user clicks on the link to account.jsp in home.htm, same as (2)
(11) Jrun sends login.htm to user, and user submits corrent id/password, same as (3)
(12) Jrun authentidates/authorizes the user, and executes/sends back account.jsp, same as (4)
(13) ... continues...
Question:
There are three types of entities:
(1) jsessionID in the cookie
(2) the "session" Java object in Servlet API
(3) "session attributes", serializable objects that are created and stored in "session" object.
The general question is
(1) when each entity of the three types is generated,
(2) when the previously generated entity is detroyed,
(3) When each is re-generated with new value
Specifically, what happens in each of the 12 steps in the usage scenerio described above?
19 years ago
sonny, I copy my code below
----------------------------------
if ( tmp_name.endsWith(".doc")) {
response.setContentType("application/msword; name=\""+ele.upload_location+"\"");
}
else if ( tmp_name.endsWith(".pdf")){
response.setContentType("application/pdf; name=\""+ele.upload_location+"\"");
}
else if ( tmp_name.endsWith(".ppt")){
response.setContentType("application/vnd.ms-powerpoint; name=\""+ele.upload_location+"\"");
}
else if ( tmp_name.endsWith(".xls")){
response.setContentType("application/vnd.ms-excel; name=\""+ele.upload_location+"\"");
}
else {
response.setContentType("application/download; name=\""+ele.upload_location+"\"");
}
// response.setContentType("application/whatever; name=\""+ele.upload_location+"\"");
// response.setHeader("Content-Disposition",
// "attachment; filename=\""+ele.upload_location+"\";");
response.setHeader("Content-Disposition: ",
"attachment; filename="+ele.upload_location +";");
OutputStream os = response.getOutputStream();
int i;
while ((i = is.read()) != -1) {
os.write (i);
}
...............
---------------------------------
please compare that with my original code. but more importantly, I had IE 5.5 with sp1 which has bugs. I downloaded sp2 and the problem goes away. I didn't test my original code with sp2, so don't know whether the subtle changes also contribute to the fix.
for the "endWith", I guess it doesn't matter much with the new versions of browser, it seems both Netscape and IE of new versions correctly recognize the suffix of the document name in the URL.
19 years ago
I have trouble to make my download servlet work in Internet Explore. I have gone through all the previous postings and done some research on the internet, but still can't figure out the solution. <br>
I have a jsp page called "download.jsp" which contains a URL to download a file from the server, and I wrote a servlet (called DownloadServlet) to look up the corresponding file from the database based on the URL and write the file to the HTTP output to send it back to the browser. <br>
the URL in download.jsp is coded like <a href="/download/<%= currentDoc.doc_id %>/<%= currentDoc.name %>">
on the browser, it will be sth like <a href="/download/87/myfile.doc">, the number 87 is my internal unique number for a file, and "myfile.doc" is the real document name. <br>
in my web.xml, "/download/" is mapped to DownloadServlet <br>
the downloadServlet.java looks like
-----------------------------------------
tem_name = ... //read DB for file name
// set content type
if ( tmp_name.endsWith(".doc")) {
response.setContentType("application/msword");
}
else if ( tmp_name.endsWith(".pdf")){
response.setContentType("application/pdf");
}
else if ( tmp_name.endsWith(".ppt")){
response.setContentType("application/vnd.ms-powerpoint");
}
else if ( tmp_name.endsWith(".xls")){
response.setContentType("application/vnd.ms-excel");
}
else {
response.setContentType("application/download");
}
// set HTTP header
response.setHeader("Content-Disposition",
"attachment; filename=\""+tmp_name+"\"");
OutputStream os = response.getOutputStream();
//read local file and write back to browser
int i;
while ((i = is.read()) != -1) {
os.write (i);
}
os.flush();
------------------------------------------
Everything works fine in Netscape 7.0, when I click on the link, Netscape prompts me to choose "open using Word" or "save this file to disk". That's exactly the behavior I want. <br>
However in IE 5.50, the behavior is VERY STRANGE.
First, when I click on the URL, the popup window asks me to "open the file from its current location" or "save the file to disk". It also says "You have chosen to download a file from this location, ...(some url).. from localhost"
(1) If I choose "save the file to disk", it will save the rendered "download.jsp" (ie, the currect page with URL I just clicked, which isn't what I want).
(2)But if I choose "open the file from its current location", the 2nd popup window replaces the 1st, which also has the "Open ..." and "Save.." options, but it says "You have chosen to download a file from this location, MYFILE.doc from localhost". (notice it shows the correct file name now)
(3) If I choose "Save..." on the 2nd window, IE will save the correct file which is "myfile.doc"; if I choose "Open ...", a 3rd replaces the 2nd window, and they look the same, and when I choose "Open..." on the 3rd window, IE will use Word to open it.
any ideas?
19 years ago
I have trouble to make my download servlet work in Internet Explore. I have gone through all the previous postings and done some research on the internet, but still can't figure out the solution. <br>
I have a jsp page called "download.jsp" which contains a URL to download a file from the server, and I wrote a servlet (called downloadServlet) to look up the corresponding file from the database based on the URL and write the file to the HTTP output to send it back to the browser. <br>
the URL in download.jsp is coded like <a href="http://localhost:8100/download/<%= currentDoc.doc_id %>/<%= currentDoc.name %>">
on the browser, it will be sth like <a href="http://localhost:8100/download/87/myfile.doc">, the number 87 is my internal unique number for a file, and "myfile.doc" is the real document name. <br>
in my web.xml, /download/ is mapped to downloadServlet <br>
the downloadServlet.java looks like
-----------------------------------------
tem_name = ... //read DB for file name
if ( tmp_name.endsWith(".doc")) {
response.setContentType("application/msword");
}
else if ( tmp_name.endsWith(".pdf")){
response.setContentType("application/pdf");
}
else if ( tmp_name.endsWith(".ppt")){
response.setContentType("application/vnd.ms-powerpoint");
}
else if ( tmp_name.endsWith(".xls")){
response.setContentType("application/vnd.ms-excel");
}
else {
response.setContentType("application/download");
}
// set HTTP header
response.setHeader("Content-Disposition",
"attachment; filename=\""+ele.upload_location+"\"");
OutputStream os = response.getOutputStream();
//read local file and write back to browser
int i;
while ((i = is.read()) != -1) {
os.write (i);
}
os.flush();
------------------------------------------
Everything works fine in Netscape, but in IE, when I click on the URL, it downloads the "download.jsp" file instead of the "myfile.doc". It will work if I right click and choose "save file as ...".
Please help me.
thanks,
Peter
19 years ago
use a MDB (Message Driven bean) and have the servlet sending request to it, then retrieve the reply from another messge queue with a timeout setting. If the servlet times out, display the message back to the user
19 years ago
Does anyone know whether there is a tag for downloading files under some directory on the server?
19 years ago
JSP
Shawn,
Do you know any web design tools that support the tag libs? I mean sth like "drag & drop" to combine HTML stuff with the tags?
thanks,
Peter
19 years ago
JSP
Andrew,
My friend bought your book and I read the first few chapters. I was glad to know I "invented" almost the same techniques for page navigation, error checking, etc. After finishing those chapters, I'm assured that my approaches were industry-strengthy.
However, I'd like to know more about how other people do logging and monitoring with web apps. specifically (but not completely), logging should happen at which points with what data, level? how to combine logging with sending error page back to user? how should logging of error tigger notification to administrators? etc.
I feel my approaches to the above is good, but need to confirm.
BTW, I want to have my own copy of your book, and for FREE
thanks
19 years ago
JSP