• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opening document using if statement

 
orelia hans
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to attach files to my database for me to be able to retrieve those documents on the web using an id number. I used binary objects but it didn't work.
Now I am using a method to read the id from the web then open the document. I think it can work but I don't know how.
On the jsp page I have :
out.write("href='PublicationDetails.jsp?id="+ publicationNum + "'>"+publicationNum+"
");
Then on the other hand :
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:AcessCore");
publicationNumber = request.getParameter("id");
out.println(publicationNumber);
if(publicationNumber=="NNR1")
{
??? how do I open a specfic document when you click on the link?
}
else if(publicationNumber=="NRR1")
{
href="C://hello.doc"; doesn't work
}
rs.close();
s.close();
con.close();
}
catch (ClassNotFoundException e1) { }
catch (SQLException e2) { }
I have like 100 publications and I have to do this one by one. Can someone tell me how to do that? opening the document as a new window.
Any help will be so much appreciated.
Thanks
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use a java class to do db lookups and a servlet as a middle man.
"<a href='/filegetter/?id="+id

FileGetter delegates db lookups to another class, DBUtils.
If the lookup is successful, FileGetter forwards to a jsp using a requestDispatcher.
You want to read a binary file and return a string, so make a DBUtils method, static getBinaryData(), that takes a table id, and a key/value pair and returns a string with the contents of the file.
Easier said than done, I know.
Here'a a DB lookup:

To read the file, you'll need a java.io.InputStream
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic