Announcement Announcement Module
Collapse
No announcement yet.
Trouble with passing ModelAndView Object to JSP Page Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble with passing ModelAndView Object to JSP Page

    Hi,
    I am new to spring and trying to pass the ModelAndView object from the controller to the JSP page.
    Here is my controller code.
    Code:
    @RequestMapping("/login")
        public ModelAndView login() {
        	LOGGER.info("Inside LOGIN");
        	Health health = null;
        	health.setPasskey("abcd");
        	return new ModelAndView("/admin/login", "health",health);
        	/
        }
    Here is my HTML/JSP code
    HTML Code:
    <html>
    <head>
    <title>
    Health Page Login
    </title>
    </head>
     
    <body  style="overflow: auto; padding:10px;">
    <div class="sectionheader">
    	<div class="sectionheader-left"><h1>Health Page Login</h1></div>
    </div>
    <form id="command" action="mediareport" method="post">
    <div class="formlayout">
    <fieldset title="Search" >
    	<div class="formelements">
    		<div class="floatleft" style="clear:both;">
    			<label style="width:200px;">Please enter password:</label>
    			<input type="Password" name="Password" size="10"></input>
    			<INPUT TYPE="HIDDEN" NAME="key" <c:out VALUE="${health.getPasskey}" /> </INPUT>
    			<input type="submit" value="Login" name="submit" />
    		</div>
    	</div>
    </fieldset>
    </div>
    </form>
    
    </body>
    </html>
    on the mediareport page...when I am trying to get the value of variable ${health.getPasskey} via request.getParameter("key"); it displays ${passkey} instead of "abcd". Please help me regarding this....
    Last edited by sumittyagi; Apr 24th, 2011, 10:48 PM.

  • #2
    Hi,

    Try
    Code:
    <INPUT TYPE="HIDDEN" NAME="key"  VALUE="${health.passkey}" />
    instead. Where "passkey" is a property in the health class.

    Comment


    • #3
      Is there any reason you're not looking into Spring Security? You'll probably save a lot of time and work if you use this instead of implementing your own.

      Comment


      • #4
        Still not working...

        Here is my controller code..
        Code:
        @RequestMapping("/login")
            public ModelAndView login() {
            	LOGGER.info("Inside LOGIN");
            	
            	Health health = null;
            	health = healthLogic.getHealthPasskey();
            	
            	return new ModelAndView("/admin/login", "health",health);
        Here is the code for getHealthPasskey() in HealthLogic Class
        Code:
        public Health getHealthPasskey(){
            	Health health = new Health();
            	health.setPasskey("abcd");
            	return health;
            	
            }
        Here is the HTML
        HTML Code:
        <html>
        <head>
        <title>
        Health Page Login
        </title>
        </head>
         
        <body  style="overflow: auto; padding:10px;">
        <div class="sectionheader">
        	<div class="sectionheader-left"><h1>Health Page Login</h1></div>
        </div>
        <form id="command" action="mediareport" method="post">
        <div class="formlayout">
        <fieldset title="Search" >
        	<div class="formelements">
        		<div class="floatleft" style="clear:both;">
        			<label style="width:200px;">Please enter password:</label>
        			<input type="Password" name="Password" size="10"></input>
        			<INPUT TYPE="HIDDEN" NAME="key"  VALUE="${health.passkey}" />
        			<input type="submit" value="Login" name="submit" />
        		</div>
        	</div>
        </fieldset>
        </div>
        </form>
        
        </body>
        </html>
        When I am trying to get the value of health.passkey by request.getParameter("key"), it is still printing "${health.passkey}" ....
        Any idea...

        Comment


        • #5
          I assume this is an example app, otherwise I agree about using Spring Security.

          But for your issue, what is your view resolver config?

          As a general tip, I recommend looking at the Pet Clinic code and what Spring Roo generates.

          Comment

          Working...
          X