I need a single page with a file upload and a text area where the contents of the file are printed in this page.
At the moment I have a jsp file and a servlet:
Part of index.jsp :
<form action="FileReader" ENCTYPE="multipart/form-data" method="POST">
<textarea name="textinputarea" rows="14" cols="130" readonly>
Some text
</textarea>
<br> <br><tr>
<td valign="top" align="left" height="200" width="33%">
<img class="start_img" src="file_Selections.jpg"> <br>
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input type="file" name="user_file" accept="text/xml">
<input type="submit" value="Validate" /> <br>
</form>
Part of the servlet:
public void doPost(HttpServletRequest request, HttpServletResponse response)
String name = request.getParameter("textinputarea");
(...)
}else {
String otherFieldName = item.getFieldName();
String otherFieldValue = item.getString();}}
(...)
out.println("<html>");
out.println("<head>");
out.println("<title>Processing get requests with data</title>");
out.println("</head>");
// body section of document
out.println("<body>");
while ((strLine = br.readLine()) != null) {
// Print the content on the console
out.println(strLine + "</br>");
}
out.println("</body>");
// end of html document
out.println("</html>");
out.close();
} catch (Exception e) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
};
}
This actually prints the content of file in a new page. I tried to give the same name of text area and the "String name = request.getParameter("textinputarea"); "..
Thanks for your time!