So, after a lot of trial and error, I finally got a server up and running along with an example servlet.
I'm trying to make it so that you can enter a song and artist and press submit and my java program will read the information.
The information I want is from a form on a JSP page. The code is here:
<form>
<input type="text" placeholder="Enter Song"/>
<input type="text" placeholder="Enter Artist"/>
<input type="submit" value="Submit" formmethod="post" formaction="GetSongAndArtist"/>
</form>
Now, I have this written already for my servlet code, but I'm just unsure what I need to do to finish it:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet GetSongAndArtist</title>");
out.println("</head>");
out.println("<body>");
BufferedReader br = request.getReader();
out.println("<h2>" + br.read() + "</h2>");
out.println("<h1>Servlet GetSongAndArtist at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
So my questions are, will the information that the user writes in the text boxes automatically be included in the HTTP post request? Also, what would be the best way of reading the information?