Filename=WriteAttribute.java
package def13;
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class WriteAttribute extends HttpServlet
{
public
void doGet(HttpServletRequest req, HttpServletResponse res) throws
IOException,ServletException
{
res.setContentType("Text/html");
PrintWriter
out=res.getWriter();
out.println("<h1>WriteAttribute</h1>");
HttpSession
session=req.getSession();
session.setAttribute("attribute3","Sessionvalue");
req.setAttribute("attribute1","requestvalue");
ServletContext
application=this.getServletContext();
application.setAttribute("attribute2","Applicationvalue");
RequestDispatcher
dis=req.getRequestDispatcher("/ReadAttribute");
dis.forward(req,res);
//RequestDispatcher
diss=req.getRequestDispatcher("/def13/ScopVariableAccess.jsp");
//diss.forward(req,res);
}
}
Filename=ReadAttribute.java
package def13;
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class ReadAttribute extends HttpServlet
{
public
void doGet(HttpServletRequest req, HttpServletResponse res) throws
IOException,ServletException
{
res.setContentType("Text/html");
PrintWriter
out=res.getWriter();
out.println("<h1>ReadAttribute</h1>");
String
request=(String)req.getAttribute("attribute1");
ServletContext
app=this.getServletContext();
String
appval=(String)app.getAttribute("attribute2");
HttpSession
session=req.getSession();
String
sessionval=(String)session.getAttribute("attribute3");
out.println("request="+request+"<br>");
out.println("App="+appval+"<br>");
out.println("Sessionvalue="+sessionval);
}
}
Filename-ScopeVariableAccess.jsp
<html>
<body>
<h1> Scoping Vriable Testing</h1>
RequestObjectValue:-
${attribute1}
<br>
ApplicationObjectValue:-
${attribute2}
<br>
Sessionvalue=
${attribute3}
</body>
</html>
Output
ReadAttribute
request=requestvalueApp=Applicationvalue
Sessionvalue=Sessionvalue
No comments:
Post a Comment