web.xml中的servlet-mapping

J2EE 码拜 9年前 (2015-05-10) 734次浏览 0个评论
 

web.xml中
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.ee</url-pattern>
  </servlet-mapping>

在jsp中
<html:form action=”HelloWorld.o” focus=”userName” >
按理说应该运行有问题,但为什么能正常运行呢?
不是应该html:form action 的后缀名和url-pattern设置一致,才可以吗?困惑?

代码贴全点看看
web.xml
<web-app>
<!– Standard Action Servlet Configuration  –>
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
     <load-on-startup>2</load-on-startup>
  </servlet>

  <!– Standard Action Servlet Mapping –>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.ee</url-pattern>
  </servlet-mapping>
    
 <!– The Usual Welcome File List –>
  <welcome-file-list>
    <welcome-file>hello.jsp</welcome-file>
  </welcome-file-list>

</web-app>

hello.jsp
<%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″
    pageEncoding=”UTF-8″%>
<%@ taglib uri=”http://struts.apache.org/tags-html” prefix=”html” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
  <head>
    <title>Hello</title>
    <html:base/>
  </head>
  <body bgcolor=”white”>     Hello
    <html:form action=”HelloWorld.w” focus=”userName” >
    </html:form>     
  </body>
</html>

  mei you chu li
顶一下
引用 3 楼 huaye2007 的回复:

mei you chu li

???什么意思

你的ActionServlet的有效路径是以.ee结尾的它才处理, 你搞个.o结尾的ActionServlet是不会理你的.!你的项目中没有.o结尾的路径的话就会告诉你找不到路径的的.!
引用 6 楼 izard999 的回复:

你的ActionServlet的有效路径是以.ee结尾的它才处理, 你搞个.o结尾的ActionServlet是不会理你的.!你的项目中没有.o结尾的路径的话就会告诉你找不到路径的的.!

你说的这个我知道,你没看清我的问题。我的意思是像我那样写应该报错,但实际上能正常运行,我不知道是怎么回事,清缓存也还是能运行

顶,顶,顶,顶
期待人解答这个问题好怪异啊
难道这样配置运行以后他也可以正常提交表单到你的action?
5分
<welcome-file>hello.jsp</welcome-file>
你的这个hello.jsp是默认的页面,显示是可以的,你提交一下才能看到效果。
20分
引用楼主 mauresmo 的回复:

web.xml中
  <servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>*.ee</url-pattern>
  </servlet-mapping>

在jsp中
<html:form action=”HelloWorld.o” focus=”userName” >
按理说应该运行有问题,……

和你说,不要说 .o,w…就算你action不写 .***后缀都行。ActionServlet都能给你识别出来。
就是说
<html:form action=”HelloWorld” focus=”userName” >  一样可以正确提交到你对应的Action

这个是ActionServlet保证的。只要你的前缀在config里面找的到就可以了。给不给全名都没所谓。

struts1貌似用的人少
8分
你web.xml里面filter-mapping才是过滤你action的。
7分
如果没有做跳转是不会出错的

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明web.xml中的servlet-mapping
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!