Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Which Driver to write a file ?

ligangligang Member Posts: 76
follow JSP is reading from request and write to a file on C:
But I am not sure it's writing to server or client . My understanding is it should write to the server , it that right ?


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Form_Post extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter toClient=res.getWriter();
String mystr="";

try
{
String surveyName=req.getParameterValues("survey")[0];
String resultsDir="C:";
FileWriter resultsFile = new FileWriter(resultsDir+
System.getProperty("file.separator") +surveyName+".txt",true);
PrintWriter toFile = new PrintWriter(resultsFile);

toFile.println("");
Enumeration values = req.getParameterNames();
while (values.hasMoreElements())
{
String name = (String)values.nextElement();
String value = req.getParameterValues(name)[0];
if (name.compareTo("submit") !=0)
{
toFile.println(name + ": " + value);
mystr = mystr + name + ": " + value +"
";
}
}
toFile.println("");

resultsFile.close();
toClient.println("");
toClient.println("Thank you!");
toClient.println("Thank you for participating");
toClient.println("

"+mystr+"

");
toClient.println("");
}
catch(IOException e)
{
e.printStackTrace();
toClient.println("A problem occured");
}
toClient.close();
}


}

Comments

  • jakemcbeerjakemcbeer Member Posts: 10
    Yes, it writes to the server because servlets only execute on the server and only send a standard http response to the client that may include html and javascript. The servlet will not execute on the client.
Sign In or Register to comment.