我目前的系统用struts1.0。我想实现一个功能,
当[点歌]按钮按下的时候,就去另外一个server取歌曲
模仿百度。如果取不到(百度server就返回http 404错误)我就在自己的画面上面报错。
如果百度server上面有,就让百度server帮我重定向request.我的实现方法:
在自己的server中做了一个doGetSongAction,里面用httpClient连接百度HttpMethod method = new GetMethod("http://mp3.baiduserver.com/word=first+love");
method.setRequestHeader("Content-type", "text/html; charset=utf-8");
HttpClient httpclient = new HttpClient();
httpclient.setTimeout(2000);
int result = httpclient.executeMethod(method);
if(result != 200){
    //go to error page;
}
百度server那边我自己写了一个servlet:public void doGet(HttpServletRequest request, 
                    HttpServletResponse response) 
                    throws ServletException, IOException{
        response.setContentType("text/html;charset=utf-8");
        out.println("Recieved successly:");
        response.sendRedirect("http://localhost:8080/getMp3/word=firstlove");
}现在的问题是:
百度server的response.sendRedirect为什么不起作用。我的画面还是停留在
http://localhost/test/doGetSongAction.do上面呢?

解决方案 »

  1.   

    可能的原因是我的doGetSongAction里面有这么一句话,
    return mapping.findForward("success");
    所以,无法重定向到
    http://localhost:8080/getMp3/word=firstlove
    上面去。但是doGetSongAction继承action类,最后一定要
    return mapping.findForward("success");的。。如何解决啊?
      

  2.   


    根据你贴出来的代码来看,你并没有重定向到doGetSongAction.do,而是重定向到getMp3这个类,你看你的strutsConfig.xml里边的配置,是不是写错了!
    getMp3对应的是doGetSongAction.do吗?
      

  3.   

    你可试着定一个业务util类,来解决这个问题,不一定非得是在action中吧!
      

  4.   

    response.sendRedirect("http://localhost:8080/getMp3/word=firstlove");
    这个重定向是另外一台server的东西,不是strutsresponse.sendRedirect不是可以控制客户端的浏览器重定向嘛。所以用这种方法。
      

  5.   

    业务util类如何来实现呢?我现在的需求是如下步骤1,画面点按钮
    用window.open('/doGetSongAction','newWindow')开个新窗口
    2,在doGetSongAction中用httpClient连接百度server服务器
    3,根据百度server服务器的返回的http code信息来判断,
    如果是http 404就要自己报自己的错误画面出来
    4,如果百度server上面有这个歌曲,就播放这个歌曲。因为歌曲具体放在什么地方,我不知道,所以先要去和百度server进行通信。
    而且这个重定向的处理是在百度server来完成的。
    如果是百度server把url返回给我,我来重定向就非常容易了
      

  6.   

    换个角度问一下,struts-config.xml里面配置的
    <forward name="success" path="/test.do" />
    这里的不能配置到别的server上面吗?
    比如
    <forward name="success" path="www.baidu.com" />