I am trying to send a string from a Java servlet to JSP but I always get a null in the string
Test.java
servlet:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String s = "HelloWolrd";
System.out.println(s);
response.setContentType("text/jsp");
request.setAttribute("s", s);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/test.jsp");
dispatcher.forward(request,response);
}
test.jsp
<body><%= request.getAttribute("s")%> </body>
web.xml
has servlet class mapped to apis. Test and url-pattern as /test
.