I am ultimately trying to change the server response that I receive, which I understand is declared in the doPost() method. I have successfully set up a server interaction in this example, however I changed the server response per the code below:
public class MyServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Please use the form to POST to this url");
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String name = req.getParameter("name");
resp.setContentType("text/plain");
if(name == null) {
resp.getWriter().println("Please enter a name");
}
resp.getWriter().println("A test to change text" + name);
}
}`
Can someone explain how I change the response I receive? I tried to simply change the text in this example, yet I would also like to find out how to receive an int or boolean as well.
I am ultimately trying to change the server response that I receive, which I understand is declared in the doPost() method. I have successfully set up a server interaction in this example, however I changed the server response per the code below:
Can someone explain how I change the response I receive? I tried to simply change the text in this example, yet I would also like to find out how to receive an int or boolean as well.