Struts 2和Atmosphere的集成(不触发动作)

时间:2014-04-28 11:49:43

标签: java tomcat struts2 atmosphere

实际上我正在尝试配置氛围和struts2,我已经从网上跟踪了很多内容,最后得出结论,Meteor扩展应该用于struts2。我已经配置了struts2和atmospehere,如下所示。它部署在tomcat中没有任何错误,但是没有从index.jsp页面触发操作。我试图调试,但认为请求没有达到struts.xml文件。任何人都可以显示请求登陆的位置或帮助我在struts.xml文件中触发操作。

web.xml

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

<display-name>Archetype Created Web Application</display-name>

<servlet>
    <servlet-name>MeteorServlet</servlet-name>
    <servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
    <init-param>
        <param-name>org.atmosphere.filter</param-name>
        <param-value>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.useWebSocket</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.useNative</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>MeteorServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<error-page>
    <location>/404page.jsp</location>
</error-page>

struts.xml中

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <package name="lms" extends="struts-default">

        <action name="save" class="com.pkg.action.UserAction" method="saveUser">
            <result name="success">/404page.jsp</result>
        </action>
    </package>


<!--   <package name="ajax" namespace="/ajax" extends="struts-default" >
        <action name="ajaxMeteor" class="com.pkg.action.MeteorAction" method="execute">
        <result name="success">/index.jsp</result>
   </action>
   </package> -->

</struts>

UserAction.java(Action Class)

package com.pkg.action;

import org.atmosphere.cpr.AtmosphereFramework;
import org.atmosphere.cpr.AtmosphereHandler;

import com.opensymphony.xwork2.ActionSupport;

  public class UserAction extends ActionSupport {

/**
 * 
 */
private static final long serialVersionUID = 1L;


AtmosphereFramework atmosphere = new AtmosphereFramework();



public String execute() throws Exception {


    return super.execute();
}

public String saveUser()
{

    addActionMessage("Save Successful");
    return SUCCESS;
}

}

的index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<body>
<h2>Hello World!</h2>

<s:form action="save" method="post">
        <label for="event_id">NAME : </label>
        <input type="text" name="" />           
        <input type="submit">
</s:form>

<h1><s:actionmessage/></h1>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

这个:<input type="text" name="" />无效,给它起一个名字,用getter和setter在动作中创建相关的属性,或者从html中删除它,然后重试。

答案 1 :(得分:0)

我修改了web.xml并添加了一个过滤器以及init param org.atmosphere.filter,否则我将导致错误。

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

<display-name>Archetype Created Web Application</display-name>

<servlet>
    <servlet-name>MeteorServlet</servlet-name>
         <servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
    <init-param>
        <param-name>org.atmosphere.filter</param-name>
        <param-value>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</param-value>
    </init-param> 
    <init-param>
        <param-name>org.atmosphere.useWebSocket</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.useNative</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.cpr.packages</param-name>
        <param-value>org.atmosphere.samples</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>MeteorServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


<error-page>
    <location>/404page.jsp</location>
</error-page>

`