从弹出窗口重定向到控制器类

时间:2014-07-15 20:53:34

标签: javascript spring

我使用Spring控制器,jsp作为视图,使用javascript和html作为前端视图。我有弹出窗口,当我提交按钮时,它应该重定向到控制器类。

带有html的JavaScript代码:

    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      $("button").click(function(){
        $("p").hide();
      });
    });
    loginQB = function(){
        var win = window.open('about:blank', 'popup', 'width=640,height=580,resizeable,scrollbars');
        <!-- win.document.write('<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>');
        win.document.write('<form:form id="qblogin" method="POST" action="/asi/mappings">');--!>
        win.document.write('<br>Sign in with Intuit Account or <a href="www.intuit.com">CreateOne</a>');
        win.document.write('<br><input type="text" name="userName">');
        win.document.write('<br><input type="password" name="password">');
        win.document.write('<br><input type="submit" value="Submit">');
        <!--win.document.write('</form>');-->
    }
    </script>
    </head> 
<body>
 <form:form id="qblogin" method="POST" onsubmit="loginQB(); return false;">
   <select name="quickbooks" id="qb" >
    <option value="qb-1">Books Desktop</option>
  </select>
    <input type="submit" value="Submit">        
    </form:form>
</body>
</html>

Spring控制器类:

@Controller
@SessionAttributes("mappingSession")
public class MappingsController {

    @RequestMapping(value="/mappings", method = RequestMethod.POST)
    public String dataMappings(Model model) throws Exception {
        DefaultHttpClient httpClient = new DefaultHttpClient();

1 个答案:

答案 0 :(得分:0)

首先,为什么不使用Bootstrap Modal弹出窗口。

http://getbootstrap.com/javascript/#modals

其次,当您提交时,您可以从表单中获取信息,将其序列化,然后将其传递给控制器​​。

http://api.jquery.com/serialize/

我强烈建议您更改弹出窗口的实现。