سؤال

Actually i am trying to configure atmosphere and struts2, i have followed a lot of contents from web and finally concluded that Meteor extension should be used for struts2. I have configure struts2 and atmospehere as below.It is deployed in tomcat without any error, but action is not triggered from index.jsp page. I tried to debug but think the request didn't reached to struts.xml file. Can any one can show where the request is landing or help me to trigger a action in struts.xml file.

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

I modified web.xml and added a filter along with init param org.atmosphere.filter included otherwise i will cause error.

<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>

`

نصائح أخرى

This: <input type="text" name="" /> is not valid, give it a name and create the related properties in the action with getter and setter, or strip it from the html, and retry.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top