Note that there are some explanatory texts on larger screens.

plurals
  1. POAuthentication Filter in java, help me in removing this error
    primarykey
    data
    text
    <p>the error comes at "<code>session = request.getSession();</code>" when i alter <code>dofilter()</code> method as a normal method <code>"dofilter(HttpServletRequest request, HttpServletResponse response)</code>" then i have to make a real "<code>dofilter(ServletRequest request, ServletResponse response)</code>" method.</p> <pre><code>package pk.edu.zab.cs; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.*; /** * Servlet Filter implementation class AuthenticationFilter */ public class AuthenticationFilter implements Filter { /** * Default constructor. */ public AuthenticationFilter() { // TODO Auto-generated constructor stub } /** * @see Filter#destroy() */ public void destroy() { // TODO Auto-generated method stub } /** * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // TODO Auto-generated method stub // place your code here String username = request.getParameter("username"); String password = request.getParameter("password"); HttpSession session = null; RequestDispatcher dispatcher = null; if (("admin".equalsIgnoreCase(username) &amp;&amp; "mypass".equals(password))) { session = request.getSession(); //the error comes here but when i remove i have to make this dofilter() method as a normal method which use HttpServletRequest and afterwards I have to make the original dofilter() method with ServletRequest. session.setAttribute("username", username); dispatcher = request.getRequestDispatcher("Welcome.jsp"); } else { dispatcher = request.getRequestDispatcher("failure.jsp"); } dispatcher.forward(request, response); // pass the request along the filter chain chain.doFilter(request, response); } /** * @see Filter#init(FilterConfig) */ public void init(FilterConfig fConfig) throws ServletException { // TODO Auto-generated method stub } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload