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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程