I have a html file which needs to take two servlet parameters the rest is hardcoded and then save itself to then send within a Javamail.
JSP getting parameters:
RequestDispatcher rd = getServletContext().getRequestDispatcher(
"/email.jsp");
rd.forward(request, response);
Your User Number is "<em><%=request.getParameter("USERNO")%></em>"
and your password is "<em><%= request.getParameter("PASSWORD")%></em>".
Just to confirm the servlet does give the parameters successfully when executed. The output of the jsp into the html file is given when I call a url like:
localhost/MailServlet/HTMLEmail?USERNO=1&PASSWORD=TEST
My idea was to save the bytes of the jsp output into a html file and then send that html file as an email. The thing is that when I try to copy from the url it becomes an infinite loop of where I cam calling the servlet.
Copying bytes code:
System.out.println("opening connection");
URL url = new URL("http://localhost:8080/MailServlet/HTMLEmail?USERNO="+USERNO+"&PASSWORD="+PASSWORD");
System.out.println("urlString created with URL="+url);
InputStream in = url.openStream();
System.out.println("InputStream opened");
FileOutputStream fos = new FileOutputStream(new File("C:/Users/****/workspace/HtmlMailServlet/WebContent/email.html"));
System.out.println("FileOutputStream opened");
System.out.println("reading file...");
int length = -1;
byte[] buffer = new byte[1024];
// buffer for portion of data from connection
while ((length = in.read(buffer)) > -1) {
fos.write(buffer, 0, length);
}
System.out.println("file read...");
fos.close();
in.close();
System.out.println("file was downloaded");
Currently I am using a crazy 3 page string with two parameters passed inside which is obviously not good to look at but does the job. Any help is appreciated.