机房监控 辐射:jsp怎么调用servlet

来源:百度文库 编辑:中科新闻网 时间:2024/04/27 21:16:52

在你的WEB-INF目录下的web.xml
添加类似信息
<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<!-- JSPC servlet mappings start -->

<servlet>
<servlet-name>test.myfirst_jsp</servlet-name>
<servlet-class>test.myfirst_jsp</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>test.myfirst_jsp</servlet-name>
<url-pattern>/myfirst</url-pattern>
</servlet-mapping>

<!-- JSPC servlet mappings end -->

</web-app>

本例中servlet为myfirst_jsp.class在test包中
访问的方法为http://你的服务器地址:端口/myfirst
如法炮制即可

比如jsp有个form表单里面有action属性,当你触发提交时,action里的属性就是访问某个servlet;/business、/test;这个就需要你在web.xml里面配置servlet

例如:

<servlet>
  <servlet-name>servletTest</servlet-name>
  <servlet-class>ServletTest</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>servletTest</servlet-name>
    <url-pattern>/test</url-pattern>
</servlet-mapping>

这样访问,就能到具体的某个servlet了

如楼上的所说