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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)