<分区>
在我的 jsp 中,如果我调用 <form action="/sampleServlet" method="get" name="form1">
,我得到以下异常:
http 404 error--sampleServlet is not found.I set sampleServlet in web.xml file and url-pattern also set to /sampleServlet.
为什么我收到 404(未找到 servlet。)?
<分区>
在我的 jsp 中,如果我调用 <form action="/sampleServlet" method="get" name="form1">
,我得到以下异常:
http 404 error--sampleServlet is not found.I set sampleServlet in web.xml file and url-pattern also set to /sampleServlet.
为什么我收到 404(未找到 servlet。)?
最佳答案
当您在 HTML 中使用 URL 时,没有前导/它们是相对于当前 URL(即当前显示的页面)。前导/它们是相对于网站根目录的:
<form action="/context-path/sampleServlet">
或
<form action="sampleServlet">
会做你想做的。
我建议您在操作路径中动态添加上下文。 示例(在 JSP 中):
<form action="${pageContext.request.contextPath}/sampleServlet">
有了它,您将永远不必更改路径,例如,如果您移动文件或复制代码,或重命名上下文!
关于java - <表单操作 ="/sampleServlet"给我异常(exception),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16683877/
相关文章:
java - Android MediaPlayer 重置卡住 UI
java - JSP 页面和 Java Servlet 重用变量名的约定是什么?
java - 在Spring Web应用程序中运行junit时,出现错误: java. lang.IllegalStateException:无法加载ApplicationContext
java - Eclipse JRE 系统库 [J2SE-1.5]
python - 将表单数据保存到数据库并将其发送到API; Django
html - JSP - 如何从数据库呈现 html(或 jsp)代码