-
Hi I am trying to use HTTPServletRequest request.getParameter to obtain a whole file which I cut and pasted into a text box, in other word, I am trying to get a long string, but the getParameter() method only got me the first line of the file, is there a way to go around this problem?
-
you have to use the post method , i think u r currently
using get Method change it to Post
-
Here is what I have:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
//sFile the actual file not filename
sFile = request.getParameter("searchterm") ;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<body>");
out.println("<pre>");
try
{
//FileReader fr = new FileReader(sFile);
BufferedReader br = new BufferedReader(???);
StreamTokenizer st = new StreamTokenizer(br);
since I can't use a filereader class, what can I use as an argument for new BufferedReader()? Thanks.
-
I don't think that's going to work.
First of all, the return value from request.getParameter() is a String. From your first post, you said that you cut and pasted the entire contents of a file into a text box. The call to request.getParameter("searchterm") should return the entire string of the text box. You don't need to use any Readers to read it. If you want to tokenize the string, use StringTokenizer. As long as you're using the POST method in your form, you should be fine.
As a convenience to your users, you might want to consider using <input type="file"...> in your form, so that your users don't have to cut-and-paste data from a file. Also, grab a copy of O'Reilly's Servlet Programming by Jason Hunter and read the section about MultiPartRequests to read file input parameters.
Hope this helps,
Andy