通过JSP 页面调用servlet方法?

在你的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
如法炮制即可

posted @ 2012-09-19 21:18  today豆豆  阅读(737)  评论(0)    收藏  举报