今天踩了一下struts2和websocket坑

以前在 web.xml 中大多数人是这样配置的,当然我也是这样配置的

  <filter>
    <filter-name>struts</filter-name>
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

然后今天一个项目需求需要用到 websocket,然后我死活访问不到,折腾了几个小时候,终于醒悟过来,在 web.xml 中配置了过滤器,并且是过滤所有,然后尝试修改 struts.xml,多弄了一个 action

<action name="web" class="com.test.Test">
        </action>

虽说可以访问到了,但是接受不了前端发来的信息,只能创建了Test这个类的对象
,然后又想办法在web.xml中动手脚,

  <filter-mapping>
    <filter-name>struts</filter-name>
    <url-pattern>*.action</url-pattern>
  </filter-mapping>

还是访问不了,所以最后我又在类的注解哪里加了.html,方能完美解决


@ServerEndpoint("/web.html")

希望大家都不要看到我的这篇博文,哈哈

发布了9 篇原创文章 · 获赞 4 · 访问量 489

猜你喜欢

转载自blog.csdn.net/qq_35818188/article/details/101027611