Filters

Published on January 2017 | Categories: Documents | Downloads: 53 | Comments: 0 | Views: 318
of 1
Download PDF   Embed   Report

Comments

Content

<html>
<body bgcolor=green>
<br><br>
<center>
<form action="/hello.sd">
Enter name<br>

<input type="text" name="name"><br>
<input type="submit" value="Click here">
</form>
</center>
FILTER
</body>
</html>
HelloServlet.java

package com.javasree;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

FILTER

public class HelloServlet extends HttpServlet
{
public void init(ServletConfig sc)
{
System.out.println("Init()...of Servlet");
}
public void doGet(HttpServletRequest
req,HttpServletResponse res) throws
IOException,ServletException
{

String nm=req.getParameter("name");
String ip=req.getRemoteAddr();
System.out.println("in servlet");
System.out.println(nm);
System.out.println(ip);
String msg="this is the program related to filter...";
System.out.println(msg);
PrintWriter out=res.getWriter();
out.println("Hello welcome to Filter Example ");
out.println("Your Name is:"+nm+"<br>");
out.println("Your IP is:"+ip+"<br>");
out.println("Your MSG is:"+msg+"<br>");
}
public void destroy()
{
System.out.println("destroy()....of servlet");
}
}

HelloFilter.java
package com.javasree;
String nm=req.getParameter("name");
String ip=req.getRemoteAddr();
FILTER
import java.io.*;
System.out.println("in Filter");
import javax.servlet.*;
System.out.println(nm);
System.out.println(ip);
public class HelloFilter implements Filter
fc.doFilter(req,res);
{
System.out.println("I got the Response...Filter");
public void init(FilterConfig fc)
{
}
System.out.println("Init()...of Filter");
public void destroy()
}
{
public void doFilter(ServletRequest
System.out.println("destroy()....of Filter");
req,ServletResponse res,FilterChain fc) throws
}
IOException,ServletException
}
{
Web.xml
<web-app>
<servlet>
<servlet-name>helloservlet</servlet-name>
<servlet-class>com.javasree.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloservlet</servlet-name>
<url-pattern>/hello.sd</url-pattern>
</servlet-mapping>

<filter>
<filter-name>hellofilter</filter-name>
<filter-class>com.javasree.HelloFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hellofilter</filter-name>
<url-pattern>/hello.sd</url-pattern>
</filter-mapping>
</web-app>

FILTER

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close