Struts 2 + websocket handshake unexpected response code 404问题

在Tomcat 7和Struts 2环境下集成WebSocket时遇到了handshake响应码404的问题。解决方法包括:1) 在WebSocket依赖中设置`provided`作用域以避免与Tomcat内置实现冲突;2) 在`struts.properties`中配置排除WebSocket请求的拦截,如`struts.action.excludePattern=/wsServer`。注意配置的路径应与request.getRequestURI()匹配,避免使用正则表达式。
摘要由CSDN通过智能技术生成

环境:

tomcat 7  + Struts 2 Spring4 MyBatis 

服务端代码:

@ServerEndpoint(value = "/wsServer", configurator = GetHttpSessionConfigurator.class)
public class WsServerEndpoint {
    private static final Logger LOGGER = Logger.getLogger(WsServerEndpoint.class);
    private static final SimpleDateFormat TIME_FMT =
        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
    private static Hashtable<String, Session> sessionMap = new Hashtable<String, Session>();
    private static Hashtable<String, HttpSession> httpSessMap =
        new Hashtable<String, HttpSession>();

    /**
     * 接收到连接打开请求的处理方法.
     * 
     * @param session
     * @param config
     */
    @OnOpen
    public void onOpen(Session session, EndpointConfig config) {
        HttpSession httpSession = WsUtil.getHttpSessionFromCfg(config, "WsServerEndpoint.onClose&
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值