Announcement Announcement Module
No announcement yet.
Cannot get request.getParameter in onSubmit method Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • eva500
    started a topic Cannot get request.getParameter in onSubmit method

    Cannot get request.getParameter in onSubmit method

    I'm using latest Spring3.1

    In jsp, it sends an argument to as follow.
    Following is parts of jsp code
    <input type="button" value="Add" onclick="location.href='/springapp/userForm.htm?method=Add'"  />
    <display:column property="id" escapeXml="true" sortable="true" titleKey="<form:input path='' />"
    title="id" style="width: 25%" url="/userForm.htm?method=Edit" paramId="id" paramProperty="id"/>
    I can get the value of argument method as a Add or Edit in showUserForm method.
    But I cannot get the value of argument 'method' as a Add or Edit in onSubmit method.

    I want very simple - I want to insert or update user info. according to the value of 'method' argument
    sent from the jsp.

    Moreover, lots of methods are deprecated such as onSumit, processFormSubmit etc in Spring 3.1 API
    Are there any methods which replace these deprecated methods that I can usefully use in the controller?
    Is there any material regarding it?,
    public class UserFormController {
    	protected final Log logger = LogFactory.getLog(getClass());
    	private UserDao userDao;
    	public void setUserDao(UserDao userDao) {
    		this.userDao = userDao;
    	@RequestMapping(method = RequestMethod.GET)
    	public User showUserForm(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
    		User user = new User();
    		String method = request.getParameter("method");   // This is working! OK!
    		if(method != null)
    			System.out.println("[ showUserForm --> GET --> METHOD ] " + method);
    		if(request.getParameter("id") != null ) {
    			String id = request.getParameter("id");
    			return userDao.getUser(id);
    		} else	
    			return user;
    	public String onSubmit(@ModelAttribute("user") User user, BindingResult errors, 
    			HttpServletRequest request, HttpServletResponse response) {
    		String method = request.getParameter("method");   // This is NOT working, so print nothing the following 2 lines.
    		if(method != null)         
    			System.out.println("[ showUserForm --> POST --> METHOD ] " + method);
    		// Save to DB
    		if(method != null && method.equalsIgnoreCase("Edit")) {
    		} else {
    		return "redirect:/users.htm";
    Last edited by eva500; Mar 26th, 2012, 05:38 PM.

  • Marten Deinum
    Please use [ code ][/code ] tags when posting code that way it remains readable.

    Why should the parameter be available? There is no POST form submit going to happen so of course it isn't there.

    Leave a comment: