日期:2014-05-17  浏览次数:20802 次

jQuery form提交无法获取java后台写入的数据
前台的代码如下:

<body>
     <form id="frmV">
     <div class="divFrame">
     <div class="divTitle">请输入下列资料</div>
    
     <div class="divContent">
     <div>用户名:<br>
     <input id="username" name="username" type="text" class="txt" />
     <font color="red">*</font><br>
     <span></span>
     </div>
    
     <div>邮箱:<br>
     <input id="email" name="email" type="text" class="txt" />
     <font color="red">*</font><br>
     <span></span>
     </div>
    
     <div class="divBtn">
     <input id="sbtUser" type="submit" value="提交" class="btn" />
     </div>
    
     <div class="divData">
     </div>
     </div>
     </div>
     </form>
  </body>


js代码如下:

<script type="text/javascript">
$(function(){

var options = {
url: "http://localhost:8080/jquery/JqueryTest003Servlet",
type: "POST",
clearForm: true,
target: "#divData"
}

$("#frmV").ajaxForm(options);
});
</script>


引用的js
<script type="text/javascript" src="../js/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../js/jquery.form.js"></script>

Servlet后台如下:


public class JqueryTest003Servlet extends HttpServlet {

private static final long serialVersionUID = 445895022678314316L;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletExceptionIOException {
this.doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String username = request.getParameter("username");
String email = request.getParameter("email");
System.out.println("Username: " + username+ ";Email: " + email);

PrintWriter out = response.getWriter();
out.write("Username: " + username+ ";Email: " + email);
out.flush();
out.close();
}

}


容器是用的Tomcat, 理论应该是要在<div class="divData"></div>这里显示输入的信息,但是前台没有显示,后台也接收到了前台输入的两个字段值了
------解决方案-------------------