1

I am trying to implement forgotpassword functionality for my application.

Before Logging in, if the user forgets the password he can recover. The recoverPassword jsp file reads the email ID and sends password to the emailID.

My forgotPassword spring Controller is not getting invoked from JSP file, Whenever the user clicks on Recover Button login.jsp file is getting loaded again.

We are using Spring Security 3.0 I added ForgotPassword Hyperlink on my login Page which opens a JSP file.

recoverPass.jsp

<form name="f" action="<c:url value="/all/recoveryPassword/pass" />" method="post">
        <div class="row clear">
            <div class="value">Enter your email:</div>
            <div class="parameter">
                <input type="text" name="email"/>
            </div>
            <div style="color: #FF0000;">${message}</div>
        </div>

        <br/>

        <div class="submit"><input type="submit" name="Recover" value="Recover"/>
        </div>

        <div>
            <a href="<c:url value="/jsp/login.jsp" />">Log In</a>
        </div>
    </form>

RecoverPasswordController.java

@Controller
@RequestMapping("/recoveryPassword")
public class RecoveryPasswordController  extends BaseController {

    @Autowired
    private UserDAO usersDao;    

    @RequestMapping(value = "/pass", method =RequestMethod.POST)
    public String recoverPassword(@RequestParam("json") String json, ModelMap model){
       //Code to read the email ID check DB and send a new password in email         
        try {

        } catch (Exception e) {            
            model.addAttribute("error", true);
            return "d"; 
        }       
        return "redirect:/recoveryPasswordSuccess";
    }
}

TO Exclude the Controller from Spring Security, I added the following in applicationContext-security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">

      <http realm="Contacts Realm" use-expressions="true">
            <intercept-url pattern="/all/recoveryPassword/*" filters="none"/>
            <intercept-url pattern="/" access="permitAll"/>
    .....

and finally my web.xml

<servlet>
        <servlet-name>abc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/classes/applicationContext.xml,/WEB-INF/classes/remote-servlet.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>

<servlet-mapping>
        <servlet-name>abc</servlet-name>
        <url-pattern>/abc/*</url-pattern>
    </servlet-mapping>

Can Anyone please help me Resolve this issue, I have been trying to fix this problem from past 1 week.

4

0 回答 0