这是我的默认servlet。 代码:
@WebServlet(value="/")
public class DefaultServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String contextPath = request.getContextPath();
response.sendRedirect(contextPath+"/login.jsp");
}
}

login.jsp位于WebContent。
login.jsp代码:
<%@ 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">
<script type="text/javascript" charset="utf-8" src="js/check.js"></script>
<title>Login here</title>
</head>
<body>
<center>
<br>
<form action="login" method="post" onsubmit="return checkForm();">
<table cellspacing=0 cellpadding=2 align=center border=0 id="table" style="margin-left: 550px">
<tr>
<td align=right>userName:</td>
<td><input type="text" name="userName"
id="userName" /> </td><td><span id="userName_notice"></span></td>
</tr>
<tr>
<td align=right>userPass:</td>
<td><input type="password" name="userPass"
id="userPass" /></td><td> <span id="userPass_notice"></span></td>
</tr>
<tr>
<td colspan="2" align=right>
<input type='submit' value='sign in'>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
&#13;
var username_empty = "<span style='COLOR:#ff0000'><font size='2px'> × name in null!</font></span>";
var password_empty = "<span style='COLOR:#ff0000'><font size='2px'> × pass is null!</font></span>";
var info_right = "<span style='COLOR:#006600'><font size='2px'> √ </font></span>";
var pass_error = "<span style='COLOR:#ff0000'><font size='2px'> × </font></span>";
window.onload = function() {
document.getElementById("userName").focus();
};
/**
*
*
* @param {}
* target
* @param {}
* Infos
*/
function showInfo(target, Infos) {
document.getElementById(target).innerHTML = Infos;
}
/**
* check form
*
* @return {Boolean}
*/
function checkForm() {
var userName = document.getElementById("userName").value;
var userPass = document.getElementById('userPass').value;
if (userName == null || userName == "") {
showInfo("userName_notice", username_empty);
document.getElementById("userName").focus();
return false;
}else{
showInfo("userName_notice", info_right);
}
if (userPass == null || userPass == "") {
showInfo("userPass_notice", password_empty);
document.getElementById("userPass").focus();
return false;
}else{
showInfo("userPass_notice", info_right);
}
return true;
}
&#13;
但是当我访问login.jsp时,找到了check.js 302.JavaScript无效。 我该怎么做才能解决这个问题? 任何建议将不胜感激。
答案 0 :(得分:-1)
找到这样的js文件并确认结构。
网络的内容
--login.jsp
--js / check.js
这意味着您需要创建js文件夹并将您的js文件放在该文件夹中。