问题描述
试了好久,当页面输入框有name属性的时候,后台action可以取到参数值;但是页面输入框只有id属性,而没有name属性的时候,后台怎么也取不到参数值,无论是从request对象取还是直接绑定action方法列表,都取不到,求解?action代码:@RequestMapping(value="/showSelf/add", method={RequestMethod.GET, RequestMethod.POST})public String addContent(Long id, HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception{System.out.println("addContent!");System.out.println("id is " + id);String[] v = request.getParameterValues("id");if(v != null){System.out.println("getParameterValues is " + v[0]);}System.out.println("getParameter is " + request.getParameter("id"));//HttpServletRequest request, HttpServletResponse response, ModelMap modelMap//Enumeration<String> pNames = request.getParameterNames();//while(pNames.hasMoreElements()){//System.out.println("paramName is " + pNames.nextElement());//}return "showSelf";}页面代码:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ 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=UTF-8"><title>xx</title></head><body><form action="/myProject/showSelf/add" method="post"><input type="submit" value="新增" /><input type="text" id="id" /></form></body></html>以上代码action获取不到id为"id"的值,当页面中输入控件的id属性改为name时,后台可以取到
解决方案
我去 你连web的基本东西都没搞懂 就搞springmvc 还是脚踏实地点好
解决方案二:
request.getParameter() 这里面获取的就是 name 参数值。。。