日期:2014-05-18  浏览次数:20684 次

关于转发的问题
设想如下:
1)设立一个简单的web页面,得到用户的输入

2)将用户的输入发送到其他搜索引擎,如http://www.google.cn/search

3)得到其他搜索引擎(如google)传来的数据,并再次排列

关于第二步的代码如下(有错):
Java code

class DemoAction extends Action {
    

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        DemoForm demoForm = (DemoForm) form;// TODO Auto-generated method stub
        System.out.println("out:"+demoForm.getParam());
        //**
        RequestDispatcher requestDispatcher=request.getRequestDispatcher("http://www.google.cn/search");
        
        try {
                        [color=#FF0000]//试图转发到http://www.google.cn/search,但出错[/color]
            requestDispatcher.forward(request, response);
        } catch (ServletException e) {
            
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        return null;
    }


请问,如何转发到http://www.google.cn/search啊,谢谢

------解决方案--------------------
先用return mapping.findForward("login")进入login.jsp页面;
在login.jsp中用response.sendRedirect("http://www.baidu.com/search");