I have a username and password in jsp / jstl I tried to pass the username and password to the controller.
this is my controller class
package com.simple.controller;
import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/welcome") public class HelloController { private String name; private String password; private String user; @RequestMapping(method = RequestMethod.POST) public String printWelcome(ModelMap model) { System.out.println(user); model.addAttribute(name); model.addAttribute(password); model.addAttribute("message", "Spring 3 MVC Hello World"); return "hello"; } }
this is index.jsp with form tags and c tags
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Registration Page</title> </head> <body bgcolor="#999966"> <p> </p> <form method="POST" action="welcome"> <p><font color="#800000" size="5"> UserName:</font><input type="text" name="name" size="20"></p> <c:set var="user" value="{param.name}" scope="request"> </c:set> <p><font color="#800000" size="5"> password:</font><input type="text" name="password" size="20"></p> <p><input type="submit" value="Submit" name="B1"></p> </form> </body> </html>
I am trying to pass the user a variable (value taken from a variable name) from this form to the controller.
<c:set var="user" value="{param.name}" scope="request"> </c:set>
can any body help me how to do this with c tags.
I did using commandName = "registereduser", where the user is an object of the RegisteredUser class.
But I'm trying to just pass a variable (with c tags) I get a null value for the user in sysout
is there any way to do with c tags using a set
thank..
spring spring-mvc jstl controller
user533 Sep 27 '12 at 12:25 2012-09-27 12:25
source share