现有文件:
login.jsp、web.xml
项目目录:
http://localhost:8080/EmployeeSystem
传值方式:
login.jsp中设置: <form action="xxxxxx" method="post"></form
此action后链接,指向对应web.xml文件中的语句,而后找到对应的servlet文件
web.xml中相关设置如下:
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>SERVLETCLASS</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
其中:SERVLETCLASS为:servlet文件(.java)所在包名.类名
<servlet>与<servlet-mapping>中的<servlet-name>需保持一致
<url-pattern>即为与login.jsp中action后路径连接的地方。
但需要注意的是:login.jsp中语句<form action="这里是路径">, 这里的路径,默认地址根目录是localhost:8080/
所以若写为相对路径的格式,可直接写为“地址1”,若写作绝对路径,则需要如下:/项目名/地址1
而servlet文件中的标签<url-pattern></url-pattern>中间的默认地址根目录,则为localhost:8080/项目名
所以若需对应起来,这里则应写作<url-pattern>/地址1</url-pattern>
另外:method="post", method="get"是两种不同的传值方式。post则是通过后台传值,get是通过url地址传值