<form action="/sampleServlet";给我例外 [英] <form action="/sampleServlet" giving me exception

查看:16
本文介绍了<form action="/sampleServlet";给我例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的jsp中,如果我调用<form action="/sampleServlet" method="get" name="form1">,我得到以下异常:

In my jsp if I call <form action="/sampleServlet" method="get" name="form1">, I get the following exception :

http 404 error--sampleServlet is not found.I set sampleServlet inweb.xml 文件和 url-pattern 也设置为/sampleServlet.

http 404 error--sampleServlet is not found.I set sampleServlet in web.xml file and url-pattern also set to /sampleServlet.

为什么我得到 404(未找到 servlet.)?

Why I am getting 404 (not found servlet.)?

推荐答案

当你在 HTML 中使用 URL 时,没有前导/它们是相对于当前 URL(即当前显示的页面).使用前导/它们是相对于网站根目录的:

When you are using URL in HTML, without leading / they are relative to the current URL (ie current page displayed). With leading / they are relative to the website root :

<form action="/context-path/sampleServlet">

<form action="sampleServlet">

会做你想做的事.

我建议您在操作路径中动态添加上下文.示例(在 JSP 中):

I suggest you to add the context inside the action path dynamically. Example (in JSP) :

<form action="${pageContext.request.contextPath}/sampleServlet">

有了这个,您将永远不必更改路径,例如,如果您移动文件或复制代码,或重命名上下文!

With this you will never have to change the path, for example, if you move your file or copy your code, or rename your context!

这篇关于&lt;form action="/sampleServlet";给我例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆