public class Servlet1 extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html";
/**Initialize global variables*/
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
// The following gets the original value posted in the HTML form:
String aString = request.getParameter("sample");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
out.println("<p>Servlet 1 has received a POST. This is the reply:</p>");
out.println(aString);
out.println("</body></html>");
// This is an example of how to forward a post
RequestDispatcher rd = request.getRequestDispatcher("jsp/jsp1.jsp");
rd.include(request, response);
}
/**Clean up resources*/
public void destroy()
{
}
}
public class Servlet1 extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html";
/**Initialize global variables*/
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
// The following gets the original value posted in the HTML form:
String aString = request.getParameter("sample");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
// This shows the data from the post from choices.html
out.println("<p>Servlet 1 has received a POST. This is the reply:</p>");
out.println(aString);
out.println("</body></html>");
// This is an example of how to forward a post (in this case from choices.html to servlet2):
RequestDispatcher rd = request.getRequestDispatcher("jsp/jsp1.jsp");
rd.include(request, response);
}
/**Clean up resources*/
public void destroy()
{
}
}
我想在servlet中把数据写到response中的stream中,没想到他却输出在屏幕上了。
DataOutputStream out = new DataOutputStream(response.getOutputStream));
out.writeByte("hello");
怎么会在屏幕上输出呢?