问题已解决 不忍就此结贴 我布置一listener,如何使用response request等对象操作servlet 或 jsp页面呢? 编译器自动生成代码如下:package untitled1;import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; //import javax.servlet.http.* ; import javax.servlet.jsp.*;public class MySessionBindListenter extends HttpServlet implements HttpSessionListener, HttpSessionAttributeListener { //Notification that a session was created public void sessionCreated(HttpSessionEvent se ) {
// out.println("<html><script>alert('This is test !')</script></html>"); // throw new java.lang.UnsupportedOperationException("Method sessionCreated() not yet implemented."); } //Notification that a session was invalidated public void sessionDestroyed(HttpSessionEvent se) { // throw new java.lang.UnsupportedOperationException("Method sessionDestroyed() not yet implemented."); } //Notification that a new attribute has been added to a session public void attributeAdded(HttpSessionBindingEvent se) { //javax.servlet.ServletContext.getContext() // throw new java.lang.UnsupportedOperationException("Method attributeAdded() not yet implemented."); } //Notification that an attribute has been removed from a session public void attributeRemoved(HttpSessionBindingEvent se) { // throw new java.lang.UnsupportedOperationException("Method attributeRemoved() not yet implemented."); } //Notification that an attribute of a session has been replaced public void attributeReplaced(HttpSessionBindingEvent se) { // throw new java.lang.UnsupportedOperationException("Method attributeReplaced() not yet implemented."); } }
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
//import javax.servlet.http.* ;
import javax.servlet.jsp.*;public class MySessionBindListenter extends HttpServlet implements HttpSessionListener, HttpSessionAttributeListener
{
//Notification that a session was created
public void sessionCreated(HttpSessionEvent se )
{
// out.println("<html><script>alert('This is test !')</script></html>");
// throw new java.lang.UnsupportedOperationException("Method sessionCreated() not yet implemented.");
} //Notification that a session was invalidated
public void sessionDestroyed(HttpSessionEvent se)
{
// throw new java.lang.UnsupportedOperationException("Method sessionDestroyed() not yet implemented.");
} //Notification that a new attribute has been added to a session
public void attributeAdded(HttpSessionBindingEvent se)
{
//javax.servlet.ServletContext.getContext()
// throw new java.lang.UnsupportedOperationException("Method attributeAdded() not yet implemented.");
} //Notification that an attribute has been removed from a session
public void attributeRemoved(HttpSessionBindingEvent se)
{
// throw new java.lang.UnsupportedOperationException("Method attributeRemoved() not yet implemented.");
} //Notification that an attribute of a session has been replaced
public void attributeReplaced(HttpSessionBindingEvent se)
{
// throw new java.lang.UnsupportedOperationException("Method attributeReplaced() not yet implemented.");
}
}
implements Filter {
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void destroy() { this.encoding = null;
this.filterConfig = null; } public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
//System.out.println("request.getCharacterEncoding()"+request.getCharacterEncoding());
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null) {
request.setCharacterEncoding(encoding);
}
}
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null) {
this.ignore = true;
}
else if (value.equalsIgnoreCase("true")) {
this.ignore = true;
}
else if (value.equalsIgnoreCase("yes")) {
this.ignore = true;
}
else {
this.ignore = false;
} }
protected String selectEncoding(ServletRequest request) { return (this.encoding); }}