In the web.xml config file:
<servlet>
<servlet-name>Your Sevlet name</servlet-name>
<servlet-class>Your class </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Your Sevlet name</servlet-name>
<url-pattern>/url</url-pattern>
</servlet-mapping>
In the HTML file:
<form method="post" action="url">
</form>
Note:
1: The servlet-name in the two tags must be the same !
2: The url must be started with the '/', it stands for the webApp root directory .
3: The url in the HTML file must be the same with in the web.xml, except the char '/'
For example:
If your web.xml file was :
<servlet-mapping>
<servlet-name>Your Sevlet name</servlet-name>
<url-pattern>/YangZhiYong1/YangZhiYong2/servlet</url-pattern> //The diretories is not limited.
</servlet-mapping>
so your HTML file must write as :<form method="post" action="YangZhiYong1/YangZhiYong2/servlet">
</form>
本文详细解析了Web应用中web.xml文件中servlet配置与HTML表单提交的原理,包括servlet名称、类路径、URL映射等关键元素的使用规则,以及如何确保两者之间的协调一致。
1143

被折叠的 条评论
为什么被折叠?



