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
            })
    
    评论

报告相同问题?

悬赏问题

  • ¥20 Yolov5训练报错
  • ¥15 Unity发布gzip压缩的webgl之后让浏览器可以正常显示画面
  • ¥15 有没有人知道这种提示怎么关?现在不做ts项目了不知道咋关了,求解,现在我以前的js项目都是这种提示了
  • ¥15 为什么mysql做了碎片化处理data_free还是很高
  • ¥15 single positional indexer is out-of-bounds
  • ¥15 LSTM 模型数据量需要多少?
  • ¥15 mysql数据抓包开发报表
  • ¥15 linux系统下安装office打不开
  • ¥20 rsync脚本分发错误,文件不齐全
  • ¥15 labview顺序结构与时间延时