web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>testWebApp</display-name>
<filter>
<filter-name>MyFirstFilter</filter-name>
<filter-class>com.test.MyFirstFilter</filter-class>
<init-param>
<param-name>fp1</param-name>
<param-value>first value 1</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>MyFirstFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
MyFirstFilter.java
package com.test;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyFirstFilter implements Filter
{
String fv1 = "";
@Override
public void destroy()
{
System.out.println("MyFirstFilter.destroy()");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException
{
System.out.println("MyFirstFilter.doFilter(...)");
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse)
{
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
req.setCharacterEncoding("UTF-8");
resp.setDateHeader("Expires", -1);
resp.setHeader("Cache-Control", "no-cache");
resp.setHeader("Pragma", "no-cache");
}
filterChain.doFilter(request, response);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
System.out.println("MyFirstFilter.init(...)");
fv1 = filterConfig.getInitParameter("fp1");
}
}
MyFirstSpringClass
package com.test;
public class MyFirstSpringClass
{
public String SayHello(String name)
{
return "helo" + name;
}
/**
* Factory Method Test
* @return
*/
public static synchronized String getResourceConfig()
{
return "mystring";
}
}
0 件のコメント:
コメントを投稿