weixin_33716557 2016-03-22 10:37 采纳率: 0%
浏览 31

Struts Ajax 404错误

structs.xml file

<package name="admin" extends="struts-default" namespace="/admin">
<!-- Add Login Functionality -->
<interceptors>

<interceptor class="AdminLoginController" name="loginStack"></interceptor>
<interceptor-stack name="loginStack">
    <interceptor-ref name="loginStack" />
</interceptor-stack>
</interceptors>
<action name="testing" class="BookingsController" method = "testing">
    <interceptor-ref name="loginStack"></interceptor-ref>
    <interceptor-ref name="defaultStack" />
    <result type="stream">
        <param name="contentType">text/html</param>
        <param name="inputName">inputStream</param>
    </result>
</action>
</package>

Register.jsp file

function test()
{
    $.ajax({
        type : "Get",
        url : "testing.action",
        success : function(response)
        {
            alert("Success");
        }
    });
}

<button class="button warning" onclick="test()"  id="testApp">Testing</button>

BookingsContoller.java file

public String testing()
{
    try
    {
        return "SUCCESS";
    }
    catch(Exception e)
    {   
         return "error";
    } 
}

I am new to web development. I am trying to do a ajax call from jsp. But I am getting 404 not found error. I have added the my code snippets for reference. Please help me. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • weixin_33717298 2016-03-29 12:13
    关注

    you need to understand your config file first ,

    <result type="stream">
            <param name="contentType">text/html</param>
            <param name="inputName">inputStream</param>
        </result>
    

    means the response is expecting a "text/html" type response and the parameter inputName has a stream variable by name "inputStream" with getters and setters , that inputStream is what you should be sending in response .

    create a variable by name "inputStream" of data type say InputStream with getters and setters and then return SUCCESS .

    in ajax , put an error field , like this :

    $.ajax({
             type   :  "POST",
             url    :  "action",
             data   :  Data,
             encode :  true,
             error  :  function(){
                 what should happen on error , if ajax call itself failed to specified url.
             }
          }).done(function(status){ 
             what should happen after successful response
            })
    
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据