ajax中的url总是跳转不到servet去,求问url该怎么写,我遗漏了什么了吗?

qq_34498522 2016-05-24 01:05:08
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>欢迎登录</title>
<link rel="stylesheet" href="static/easyui/themes/default/easyui.css" type="text/css"></link>
<link rel="stylesheet" href="static/easyui/themes/icon.css" type="text/css"></link>
<link rel="stylesheet" href="static/easyui/themes/color.css" type="text/css"></link>
<link rel="stylesheet" href="static/easyui/demo/demo.css" type="text/css"></link>
</head>
<img src = "image/2.jpeg">
<body>
<div id="loginWin" class="easyui-window" title="登录" style="width:350px;height:188px;padding:5px;"
minimizable="false" maximizable="false" resizable="false" collapsible="false">
<div class="easyui-layout" fit="true">
<div region="center" border="false" style="padding:5px;background:#fff;border:1px solid #ccc;">
<form id="loginForm" method="post">
<div style="padding:5px 0;">
<label for="login">帐号:</label>
<input type="text" name="login" style="width:260px;"></input>
</div>
<div style="padding:5px 0;">
<label for="password">密码:</label>
<input type="password" name="password" style="width:260px;"></input>
</div>
<div style="padding:5px 0;text-align: center;color: red;" id="showMsg"></div>
</form>
</div>
<div region="south" border="false" style="text-align:right;padding:5px 0;">
<a class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0)" onclick="login()">登录</a>
<a class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0)" onclick="cleardata()">重置</a>
</div>
</div>
</div>
</body>

<script type="text/javascript" src="static/easyui/jquery-1.8.0.js"></script>
<script type="text/javascript" src="static/easyui/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
document.onkeydown = function(e){
var event = e || window.event;
var code = event.keyCode || event.which || event.charCode;
if (code == 13) {
login();
}
}
$(function(){
$("input[name='login']").focus();
});
function cleardata(){
$('#loginForm').form('clear');
}
function login(){
if($("input[name='login']").val()=="" || $("input[name='password']").val()==""){
$("#showMsg").html("用户名或密码为空,请输入");
$("input[name='login']").focus();
}else{
//ajax异步提交
$.ajax({
type:"POST", //post提交方式默认是get
url:"Servlet/ValidateServlet",
data:$("#loginForm").serialize(), //序列化
error:function(request) { // 设置表单提交出错
$("#showMsg").html(request); //登录错误提示信息
},
success:function(data) {
$.message.alert('Info',data, 'info');
}
});
}
}
</script>
</html>
...全文
223 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyh1203 2016-05-24
  • 打赏
  • 举报
回复
web.xml内容贴出来看下
qq_34498522 2016-05-24
  • 打赏
  • 举报
回复
引用 1楼小爷胡汉三 的回复:
url:"Servlet/ValidateServlet", 看看你的Servlet怎么配置就怎么写!还有如果需要就加上全路径试试!也就是把项目名称加上!
我的servlet是新建servlet程序的 不是新建java的 还需要自己手动去配置吗 而且其他方式跳转到该servlet是可以的
  • 打赏
  • 举报
回复
1.可以加全路径 2.看看你的拦截配置的是什么,是不是还要加。后缀
BUG胡汉三 2016-05-24
  • 打赏
  • 举报
回复
url:"Servlet/ValidateServlet", 看看你的Servlet怎么配置就怎么写!还有如果需要就加上全路径试试!也就是把项目名称加上!

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧