How Do I read in a file as text to a buffer?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 66
Reputation: mimsc is an unknown quantity at this point 
Solved Threads: 0
mimsc mimsc is offline Offline
Junior Poster in Training

How Do I read in a file as text to a buffer?

 
0
  #1
Jul 21st, 2009
I have a jsp...I need to read in the generated html fron the jsp to a string buffer I can use in a mail method

how do u do that?

test.jsp
Last edited by mimsc; Jul 21st, 2009 at 5:07 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,636
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 470
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: How Do I read in a file as text to a buffer?

 
0
  #2
Jul 22nd, 2009
You can use the URLConnection class or the Apache Commons HttpClient library to retrieve the HTML generated by your JSP; pushing it into a StringBuffer/StringBuilder is just a matter of reading the HTTP response stream.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 66
Reputation: mimsc is an unknown quantity at this point 
Solved Threads: 0
mimsc mimsc is offline Offline
Junior Poster in Training

Re: How Do I read in a file as text to a buffer?

 
0
  #3
Jul 22nd, 2009
hey thanx for the response....check me out this what I got:

I got a form called "homeSellerReport1.jsp"..that has a submit that goes to this page:

  1. <%@ page language="java" %>
  2. <%@ page import="trader.webservices.util.Utils" %>
  3. <%@ page import="trader.webservices.util.EmailSender" %>
  4. <%@ page import="trader.webservices.data.UserDataVO" %>
  5. <%@ page import="trader.webservices.data.UserInfoDAO" %>
  6. <%@ page import="trader.webservices.data.AgentInfoDAO" %>
  7. <%@ page import="java.io.DataOutputStream" %>
  8. <%@ page import="java.io.FileOutputStream" %>
  9. <%@ page import="java.io.FileInputStream" %>
  10. <%@ page import="java.io.IOException" %>
  11. <%@ page import="java.util.*" %>
  12. <%@ page import="java.net.*" %>
  13. <%@ page import="java.io.*" %>
  14.  
  15. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  16. "http://www.w3.org/TR/html4/loose.dtd">
  17. <%
  18. UserDataVO userData = null;
  19.  
  20. String username = request.getParameter("username");
  21. String password = request.getParameter("password");
  22. String format = "txt";
  23.  
  24. //String domainName = UserInfoDAO.removeHostRedirection(request.getServerName());
  25.  
  26. String adminServer = request.getServerName();
  27. String javaAdminServer = request.getServerName();
  28.  
  29. if (request.getServerName().equals("localhost") || request.getServerName().startsWith("199")) {
  30. adminServer = "cpanel.homes.com";
  31. javaAdminServer = "localhost:8080";
  32. }
  33.  
  34. userData = UserInfoDAO.getUserInfo(username);
  35.  
  36. //String address = "suggestaservice@agentadvantage.com,support@agentadvantage.com";
  37. String emailTo = request.getParameter("emailTo");
  38.  
  39.  
  40. URL httpUrl = new URL("http://" + javaAdminServer + "/JAABA/jsp/cpanel/homeSellerReport1.jsp");
  41. InputStream fis = httpUrl.openStream();
  42. byte[] bytes = new byte[fis.available()];
  43.  
  44.  
  45. fis.read(bytes);
  46. String strFileContent = new String(bytes);
  47.  
  48.  
  49. String msgBody = "Attached is the homeseller report you requested.";
  50. EmailSender emailSender = new EmailSender();
  51. emailSender.sendMailWithAttachment(emailTo,"web@homes.com","HomeSeller Report from Control Pane, Test",msgBody,strFileContent,format);
  52.  
  53. %>


but im getting this error

java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/JAABA/jsp/cpan...lerReport1.jsp
Last edited by mimsc; Jul 22nd, 2009 at 3:02 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,636
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 470
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: How Do I read in a file as text to a buffer?

 
0
  #4
Jul 22nd, 2009
Is that link accessible via the browser? Since a server error has occurred, it might pay off to see the server log for more details.

BTW, I think you are better off using a free reporting tool like Jasper Reports to create reports rather than use the JSP of your very own application. Also, moving all this business code in a separate class which would be called by the servlet would be a wise move.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 66
Reputation: mimsc is an unknown quantity at this point 
Solved Threads: 0
mimsc mimsc is offline Offline
Junior Poster in Training

Re: How Do I read in a file as text to a buffer?

 
0
  #5
Jul 22nd, 2009
Originally Posted by ~s.o.s~ View Post
Is that link accessible via the browser? Since a server error has occurred, it might pay off to see the server log for more details.

BTW, I think you are better off using a free reporting tool like Jasper Reports to create reports rather than use the JSP of your very own application. Also, moving all this business code in a separate class which would be called by the servlet would be a wise move.

nah that link is not accesible via the browser...the log's tellin me Im getting a null from that page im trying to read from because its a form that requires parameters passed to it once accessed.....so I know what the problem is.....I just dont know how to get around it
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 66
Reputation: mimsc is an unknown quantity at this point 
Solved Threads: 0
mimsc mimsc is offline Offline
Junior Poster in Training

Re: How Do I read in a file as text to a buffer?

 
0
  #6
Jul 22nd, 2009
I basically when I hit the "submit...I wanna go to that page....and have have all the rendered html from the page I was just on in a string so I can pass to that function

when I try to do that HTTP stream it wipes the page clean...thats the problem
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,636
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 470
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: How Do I read in a file as text to a buffer?

 
0
  #7
Jul 22nd, 2009
> a form that requires parameters passed to it once accessed.....so I
> know what the problem is.....I just dont know how to get around it

You can pass those form parameters in the URL [assuming you know what they are]
  1. String url = "http://localhost/MyApp/param1=value1&param2=value2";

But like I previously mentioned, all this is really hackish; you really need to come up with something better than calling your own JSP and mailing its response.
Last edited by ~s.o.s~; Jul 22nd, 2009 at 4:35 pm.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC