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">
or
<form action="sampleServlet">
will do what you want.
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!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…