Мне нужна одна страница с загрузкой файла и текстовой областью, где содержимое файла напечатано на этой странице.
На данный момент у меня есть файл jsp и сервлет:
Часть 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>
Часть сервлета:
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());
};
}
Это фактически печатает содержимое файла на новой странице.Я попытался дать то же имя текстовой области и "String name = request.getParameter (" textinputarea ");" ..
Спасибо за ваше время!