I'm just starting out with Servlets, and i'm totally stumped.
I've looked at dozens of resources online, and tried them all without success. They all (with minor variations) have a jsp file which contains this code:
<%= request.getAttribute("message")%>
...and a servlet which contains this code:
String message = "Example source code of Servlet to JSP communication.";
request.setAttribute("message", message);
getServletContext().getRequestDispatcher("/newjsp_1.jsp").forward(request, response);
I've put the above code in the doPost(), doGet(), and the body of servlet, nothing works. Then it occurred to me that there's no way the jsp file actually knows what servlet it's supposed to be communicating with. I've researched xml mapping, and annotation mapping, but they don't seem to apply.
So far I've communicated with Ajax to the servlet fine, but I can specify the action with ajax. How do I pass data from the jsp to the servlet, and then back again?
Any ideas would be appreciated!