Filter to process form data

Hello,

I am implementing MVC model for my Web project. In which i pass the values of a login web page to a servlet.

I want to implement filter which checks if user name and password are entered.

I am not sure how to call the filter from a Web page. I tied to do same was as calling a servlet but Tomcat gives exception.

my filter is

package controller;

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;

import communication.ServerComm;

publicclass InitialFilterimplements Filter{

private ServerComm server;

private FilterConfig config =null;

publicvoid init(FilterConfig config)throws ServletException{

this.config = config;

}

publicvoid destroy(){

config =null;

}

publicvoid doFilter(ServletRequest request, ServletResponse response,

FilterChain chain)throws IOException, ServletException{

//casting request response objects

HttpServletRequest req = (HttpServletRequest) request;

HttpServletResponse res = (HttpServletResponse) response;

String username = (String)request.getParameter("Username").trim();

String password = (String)request.getParameter("Password").trim();

//checks if username and password are entered.

if(username.equals("")||password.equals("")){

res.sendRedirect(req.getContextPath()+"/relogin.html");

return;

}

server =new ServerComm(username);

req.setAttribute("initserver", server);

res.sendRedirect(req.getContextPath()+"/LoginHandler");

}

}

Thanks in advance

[3408 byte] By [m_kka] at [2007-11-26 20:20:11]
# 1
you have to define the filter and its filter mapping(s) in your web.xml.
jleecha at 2007-7-10 0:44:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

jleech, you posted in this forum 4 years ago about precompiling jsp files: http://forum.java.sun.com/thread.jspa?threadID=387124&messageID=1669544

You described that someone has set up a tool that does following: Extract a .war file, precompile the jsps to .java, compile the .java to .class, and then edit the web.xml, then put it all back into a .war file for deployment.

Unfortunately the link is broken.

Could you retrieve a working link to that tool?

oxia at 2007-7-10 0:44:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...