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
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.
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:
<%@ page language="java" %>
<%@ page import="trader.webservices.util.Utils" %>
<%@ page import="trader.webservices.util.EmailSender" %>
<%@ page import="trader.webservices.data.UserDataVO" %>
<%@ page import="trader.webservices.data.UserInfoDAO" %>
<%@ page import="trader.webservices.data.AgentInfoDAO" %>
<%@ page import="java.io.DataOutputStream" %>
<%@ page import="java.io.FileOutputStream" %>
<%@ page import="java.io.FileInputStream" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
UserDataVO userData = null;
String username = request.getParameter("username");
String password = request.getParameter("password");
String format = "txt";
//String domainName = UserInfoDAO.removeHostRedirection(request.getServerName());
String adminServer = request.getServerName();
String javaAdminServer = request.getServerName();
if (request.getServerName().equals("localhost") || request.getServerName().startsWith("199")) {
adminServer = "cpanel.homes.com";
javaAdminServer = "localhost:8080";
}
userData = UserInfoDAO.getUserInfo(username);
//String address = "suggestaservice@agentadvantage.com,support@agentadvantage.com";
String emailTo = request.getParameter("emailTo");
URL httpUrl = new URL("http://" + javaAdminServer + "/JAABA/jsp/cpanel/homeSellerReport1.jsp");
InputStream fis = httpUrl.openStream();
byte[] bytes = new byte[fis.available()];
fis.read(bytes);
String strFileContent = new String(bytes);
String msgBody = "Attached is the homeseller report you requested.";
EmailSender emailSender = new EmailSender();
emailSender.sendMailWithAttachment(emailTo,"web@homes.com","HomeSeller Report from Control Pane, Test",msgBody,strFileContent,format);
%>
but im getting this error
java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/JAABA/jsp/cpanel/homeSellerReport1.jsp
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.
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
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
> 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]
String url = "http://localhost/MyApp/param1=value1¶m2=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.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.