Hi All,
In this following
servlet and
jsp program the output is displaying NULL.Is there any mistake to display my name attribute in jsp?Can anyone explain why this program is not working?Advance Thanks.
Servlet program :
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class ChkAttrib extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><body><h1>Atrribute Checking</h1><br>");
String name="Kathir";
req.setAttribute("myname",name);
RequestDispatcher view=req.getRequestDispatcher("chk1.jsp");
view.forward(req,res);
}
}
JSP code :
<html>
<head>
<title>My Attibute</title>
</head>
<body>
My name is :<%= (String)request.getAttribute("name") %>
</body>
</html>