Java 所需资源(servlet)不可用
在尝试使用Java 所需资源(servlet)不可用,java,jsp,servlets,Java,Jsp,Servlets,在尝试使用login.jsp 我在登录中有以下代码 <%@ include file="/jsp/include.jsp"%> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:
login.jsp
我在登录中有以下代码
<%@ include file="/jsp/include.jsp"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script>
function sendForm() {
document.formLogin.submit();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Example :: Spring Application</title>
</head>
<body>
<div class="container">
<form class="bs-docs-example form-horizontal"
action="ServletValidation" name="formLogin" id="formLogin"
method="post">
<legend>Login</legend>
<div class="control-group">
<label for="inputUsername" class="control-label">Email</label>
<div class="controls">
<input type="text" id="inputUsername">
</div>
</div>
<div class="control-group">
<label for="inputPassword" class="control-label">Password</label>
<div class="controls">
<input type="password" id="inputPassword">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox"> <input type="checkbox">
Remember me
</label>
<button class="btn" type="submit" action="sendForm();">Sign
in</button>
</div>
</div>
</form>
</div>
</body>
</html>
但一旦我单击“提交”按钮,它将返回:
状态HTTP404-/bt/jsp/ServletValidation
说明所需资源(/bt/jsp/ServletValidation)不可用
可用
文件夹结构如下所示:
+bt
-src
-WebContent
-jsp
-resources
-WEB-INF
-classes
*web.xml
*index.jsp
我发现的问题是,为什么它要发送到该URL?ServletValidation与ValidationServlet不同。有两个问题:
- 您的servlet映射到URL
,表单的操作设置为/ValidationServlet
ServletValidation
- 可能您的
与servlet映射不在同一级别login.jsp
请求#getContextPath()
实现:
如果在项目中不使用JSTL,那么就这样做。您应该避免在jsp中使用Scriptlet(那些在jsp中包含讨厌的Java代码的
标记)。但如果您没有,那么您应该尝试以下方法:
+bt
-src
-WebContent
-jsp
-resources
-WEB-INF
-classes
*web.xml
*index.jsp
不过,第一条路是最好的选择
更多信息:
<url-pattern>/ServletValidation</url-pattern>
/ServletValidation
您的ServletValidation
映射在哪里?如果login.jsp
在jsp
文件夹内或更深一层,这不会解决问题。是的,我忘了在这里修改jsp,但我现在在操作中使用了与Servlet相同的名称。但仍然不能正常工作,您需要给出servlet的相对路径。类似于ACTION=“/bt/ValidationServlet”@joy_绝地武士,如果你有更深层次的页面,就无法解决问题。检查我的答案以获得完整路径,然后是表单中设置操作的相对路径。我在WebContent的jsp文件夹中有jsp文件,然后我像这样编辑,现在显示相同的错误,但现在显示的是资源(/ValidationServlet)不是available@user1751981看起来您的项目中没有JSTL,或者您的Web应用程序服务器没有处理EL。访问我们的JSTL wiki页面(答案中的链接)在项目中添加库。如果你不想要(或者认为你不需要它),你可以使用第二种方法,但是我警告你,使用scriptlets不是一种可行的方法。是的,这很有效,我使用contextPath并从那里移动,并且能够找到它。谢谢,不客气。请别忘了把这篇文章标记为答案。