B
B
bychok3002017-04-11 14:02:21
Java
bychok300, 2017-04-11 14:02:21

How to display information by servlet on the same page?

there is a post method

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/html;");
    
    final String textField = request.getParameter("new");
    //final String submitButton = request.getParameter("createNew");
    
    //вызываем ответы клиенту с сервера
    final PrintWriter out = response.getWriter();
    out.print("<div>" + textField + "</div>");
    out.close();
  }


As you can see from the code, it takes a text field as input and simply displays it, but! It displays it on a new page
, that is, the starting url is localhost:8080/index.html
and after processing localhost:8080/new/
how can I make the text appear not on a new page, but on index.html

here is the index itself

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PAAATRYY</title>
</head>
<body>
  <form action="CreateEvent" method="post"> 
            <input id = "textField" type="text" name = "new" required placeholder="Hey!"/>
            <input id = "submitButt" type="submit" name = "createNew" value = "Create Event"/>         
           
  </form>
  <div></div>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kolman, 2017-04-14
@Evgeny_13

Try to call request.setAttribute("label name", "here is what you want to pass, without quotes");
And in .jsp set this label to the right place! Or use scriptlets <%=request.getAttribute("studentsList")%>.
javatalks.ru/topics/16392?page=1#78654

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question