web 页面的提交方式

1 表单提交

form 配合 submit

<form id="myform" class="form-horizontal" action= "${pageContext.request.contextPath}/register" method = "post" style="margin-top: 5px;">

<input type="submit" width="100" value="注册" name="submit" border="0" style="background: url('./images/register.gif') no-repeat scroll 0 0 rgba(0, 0, 0, 0);
height:35px;width:100px;color:white;">

</form>

 

 

2 a标签 配合 button提交

<a href="${pageContext.request.contextPath }/product?method=submitOrder">
<input type="button" width="100" value="提交订单" name="button" border="0" style="background: url('./images/register.gif') no-repeat scroll 0 0 rgba(0, 0, 0, 0);
height:35px;width:100px;color:white;">
</a>

3 a标签 配合 onclick 用java脚本提交

<script>

function clearCart()
{

if(confirm("您是否要清空购物车?"))
{
location.href="${pageContext.request.contextPath}/product?method=clearCart";

}

}

</script>

<a href="javascript:void(0);" onclick="clearCart()" id="clear" class="clear">清空购物车</a>

 

4 同步提交

<script type="text/javascript">


$(function() {
var content = "";
$
.post(
"${pageContext.request.contextPath}/product?method=categoryList",
function(data) {

//动态创建<li><a href="#">${category.cname }</a></li>
for (var i = 0; i < data.length; i++) {
content += "<li><a href='${pageContext.request.contextPath}/product?method=productList&cid="
+ data[i].cid
+ "'>"
+ data[i].cname + "</a></li>";
}

//将拼接好的li放置到ul中
$("#categoryUl").html(content);
}, "json");

});

</script>

5 异步ajax提交

 

<script  type="text/javascript">

//定义一个标志
var flag = false;

//value:输入的内容
//element:被校验的元素对象
//params:规则对应的参数值
//目的:对输入的username进行ajax校验
$.ajax({
"async":false,
"url":"${pageContext.request.contextPath}/checkUsername",
"data":{"username":value},
"type":"POST",
"dataType":"json",
"success":function(data){
flag = data.isExist;
}
});

</script>

 

上一篇:java – 静态资源的URI中的上下文路径,我真的需要指定它吗?


下一篇:java – Spring REST模拟上下文路径