0
<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>&nbsp;</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

你能告诉我我应该在表单动作中输入什么吗?因为我认为在 Spring MVC 中的表单动作中存在一些错误,我们将动作放在我上面提到的情况下。

Spring 配置文件如下:

    <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>
4

2 回答 2

0

尝试指定控制器方法返回的内容类型,将produces = "text/html"参数添加到@RequestMapping注释中。

于 2013-10-18T10:40:48.100 回答
0

将注释的method参数更改为:RequestMappingRequestMethod.POST

@RequestMapping(value="/usermaster", method = RequestMethod.POST)
public final String addUserMaster(...){
...
}

这样当您将表单提交到/usermaster使用method="POST"此方法的 URL 时,就会被执行。

您还需要有一个方法(映射到 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用户显示页面。现在,当您提交 this 时,将调用form上述方法。addUserMaster

您不必创建新的 jsp 文件。该 url/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">

现在当用户点击提交按钮时,该表单将被提交到/usermasterURL 并由addUserMaster方法处理。

于 2013-10-18T10:38:49.783 回答