<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/jquery.validate.min.js"></script>
<script>
function setHiddenVal(){
var goAhead = true;
var myVal="I am hidden value";
document.getElementById("secretValue").value = myVal;
if (goAhead == true) {
document.forms["register-form"].submit();
}
}
</script>
</head>
<body>
<!--Main Container Starts here-->
<div class="main_container">
<div class="header">
<div class="right_panel">
<h2 align="center"><u>User Master</u></h2>
<div class="top-form">
<div>
**<form:form action="/usermaster" modelAttribute="CustomerForm" id="register-form" method="POST">**
<table cellspacing="0" cellpadding="0" border="" class="form1">
<tr>
<td class="label">Name:</td>
<td>
<form:input path="firstname"/>
</td>
</tr>
<tr>
<td class="label">Password:</td>
<td>
<form:input path="password"/>
</td>
</tr>
</tbody>
</table>
<div>
<table>
<tr>
<td> </td>
<td>
<input type="button" class="btn blue px16" value="Search" />
<input type="button" name="submit" id="btnsubmit" value="Submit" onclick="setHiddenVal();"/>
<input type="button" class="btn blue px16" value="Clear" />
<input type="button" class="btn blue px16" value="Change Password" />
<input type="button" class="btn blue px16" value="Manage User Notification Profile" />
</td>
</tr>
</table>
</div>
</form:form>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</body>
</html>
so above one is my code for jsp and below is the code of controller
@RequestMapping(value={"/usermaster" }, method = RequestMethod.POST)
public final String addUserMaster(@ModelAttribute("CustomerForm") CustomerForm pricing, Map<String, Object> map,
Model model, HttpServletRequest request) {
System.out.println("the first name is "+pricing.getFirstname());
System.out.println("the password is "+pricing.getPassword());
return "usermaster";
}
@RequestMapping(value={"/showusermaster" }, method = RequestMethod.GET)
public String showPage(ModelMap model){
model.addAttribute("CustomerForm", new CustomerForm());
return "usermaster";
}
但是我的页面使用带有url的弹出窗口打开了:
C:\Users\ganganshu.s\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\YW6383E8\usermaster
所以它应该像
一样打开http://localhost:8080/enbee/usermaster
你能不能告诉我应该把什么放在表格动作中...因为我认为在弹簧MVC中的表单动作中存在一些错误我们把动作放在上面提到的情况中。
Spring confg文件如下:
<mvc:interceptors>
<bean class="com.enbee.admin.interceptor.AuthenticationInterceptor" />
<!-- Declare a view resolver-->
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="1" />
并且jsp名称是usermaster.jsp
在sidemenu.jsp中我改为:
<li><a href="<c:url value='/showusermaster'/>">User Master</a></li>
答案 0 :(得分:0)
将method
注释的RequestMapping
参数更改为RequestMethod.POST
:
@RequestMapping(value="/usermaster", method = RequestMethod.POST)
public final String addUserMaster(...){
...
}
因此,当您使用/usermaster
将表单提交到网址method="POST"
时,此方法将会执行。
您还需要有一个方法(映射到URL),该方法将向用户显示此页面。您可以使用以下方法:
@RequestMapping(value = "/showusermaster", method = RequestMethod.GET)
public String showPage(ModelMap model){
model.addAttribute("CustomerForm", new CustomerForm());
return "usermaster";
}
使用此方法,URL
http://localhost:8080/enbee/showusermaster
将向用户显示usermaster.jsp
页面。现在,当您提交此form
时,将调用上述addUserMaster
方法。
您不必创建新的jsp文件。网址/showusermaster
会将usermaster.jsp
返回给用户,用户可以在其中添加表单值并提交表单:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
...
<c:url var="submitUrl" value="/usermaster">
<form:form id="form" action="${submitUrl}" modelAttribute="CustomerForm" method="POST">
现在,当用户点击提交按钮时,此表单将提交到/usermaster
网址,并将由addUserMaster
方法处理。
答案 1 :(得分:0)
尝试指定控制器方法返回的内容类型,将produces = "text/html"
param添加到@RequestMapping
注释中。