0

I want to retrieve the parameters sent through the form login.jsp in the controller..but I am getting the error-"Request parameter is not present". My code for login.jsp is as follows:-

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>Spring Security</title>
</head>
<body>
<center>

  <h1>Welcome to Spring Security Learning</h1>
  <c:if test="${not empty SPRING_SECURITY_LAST_EXCEPTION}">
    <font color="red">
      Your login attempt was not successful due to <br/><br/>
      <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/>.
    </font>
  </c:if>

  <div style="text-align: center; padding: 30px; border: 1px solid; width: 250px;">

    <form method="post"
          action='j_spring_security_check'>

      <table>

        <tr>

          <td colspan="2" style="color: red">${message}</td>

        </tr>


        <tr>

          <td>User Name:</td>


          <td><input type="text" name="j_username" id="uname"/></td>

        </tr>


        <tr>

          <td>Password:</td>


          <td><input type="password" name="j_password" /></td>

        </tr>


        <tr>

          <td colspan="1"><input type="submit" value="Login" /></td>


          <td colspan="1"><input name="reset" type="reset" /></td>

        </tr>

      </table>

    </form>

  </div>

</center>
</body>
</html>

The code for controller is as follows:-

 @RequestMapping("/search")
    public ModelAndView search(HttpSession session2,@RequestParam("j_username") String name) {

        session2.setAttribute("name", name);
        Session session=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory().openSession();
        String hql = "SELECT E.firstName FROM User E";
        Query query = session.createQuery(hql);
        List results = query.list();

        //System.out.println(results.get(1).getClass().getFields());
        HashMap model = new HashMap();
        model.put("users", results);
        return new ModelAndView("search", model);
    }

Please help..thanx in advance..

Abhishek
  • 9
  • 1
  • before the processing of the request reaches your method `search()`, is there another method that reads the request body? A servlet filter? – JimHawkins Jun 23 '16 at 06:16
  • yes..the request is processed by a filter and then going to /search – Abhishek Jun 23 '16 at 06:21
  • you're sending the request via HTTP POST to your controller/servlet. See [this question](http://stackoverflow.com/q/10210645/1988304) for consuming data sent via POST multiple times. – JimHawkins Jun 23 '16 at 06:28

0 Answers0