Results 1 to 5 of 5

Thread: Trouble with passing ModelAndView Object to JSP Page

  1. #1
    Join Date
    Apr 2011
    Posts
    3

    Default 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 at 10:48 PM.

  2. #2
    Join Date
    Jan 2011
    Posts
    4

    Default

    Hi,

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

  3. #3
    Join Date
    Aug 2004
    Location
    UK
    Posts
    108

    Default

    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.

  4. #4
    Join Date
    Apr 2011
    Posts
    3

    Default 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...

  5. #5
    Join Date
    Feb 2007
    Location
    Huntington Beach, CA
    Posts
    26

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •