2012-04-07 71 views
-2

論壇成員從Java類jsp重定向錯誤

我困住了問題,我需要你的幫助,以儘快解決它。

其實我試圖從我的JAVA類打開JSP。

下面是我用來轉發給我需要的JSP頁面

@RequestMapping(value = "/login/GetLoginCheck.action") 
    public void sitemap (HttpServletRequest request, HttpServletResponse response) throws Exception { 
     try { 
      System.out.println("QUERY TO GET LOGIN"); 
      //response.sendRedirect(response.encodeRedirectURL("../index.jsp")); 
      request.getRequestDispatcher("/index.jsp").forward(request, response); 
      return; 
     } catch (Exception e) { 
      return; 
     } 
    } 

毫無疑問,下面的代碼執行的代碼。 但代碼執行後,而不是轉發到jsp頁面它只是顯示我在我的螢火蟲主機上的index.jsp的代碼

下面是我的螢火蟲控制檯的圖像。 enter image description here

不能理解爲什麼它不重定向到我的index.jsp頁面。

請給我一些解決方案,讓我的工作儘快完成。

+0

@sha你怎麼沒在我的問題理解添加此???你爲什麼投票否定我? – 2012-04-07 12:02:50

+0

因爲這是一種粗魯......「儘快完成我的工作」...... – sha 2012-04-07 12:39:12

+0

@sha我很抱歉沒有禮貌。我會記住這一點 – 2012-04-09 04:49:40

回答

0

我想你應該簡單地使用response.sendRedirect("/index.jsp")。請注意,根據documentation../index.jsp不是用於重定向的有效URL。

+0

你還沒有看到那條線被我註釋掉?我在我的螢火蟲控制檯上得到了index.jsp,但頁面沒有打開..你明白我的問題嗎? – 2012-04-07 10:53:09

+0

現在,我真的懷疑它。你有意使用'forward'而不是'sendRedirect',但仍然提到_「不重定向」_在你問題的最後一句中?你能忽略一些例外嗎? – nobeh 2012-04-07 11:04:58

+0

請參閱上面的答案,並嘗試幫助我解決我的問題 – 2012-04-07 11:58:51

0

在春天你必須這樣使用。更多信息here

@RequestMapping(value = "/login/GetLoginCheck.action") 
    public String sitemap (HttpServletRequest request, HttpServletResponse response) throws Exception { 
     try { 
      System.out.println("QUERY TO GET LOGIN"); 
      return "index"; 
     } catch (Exception e) { 
      return; 
     } 
    } 

dispatcher-servlet.xml

<bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix"> 
      <value>/WEB-INF/jsps/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 
+0

當我使用上面的代碼時,我得到了404錯誤。並在螢火蟲的HTML標籤中顯示我找不到**/ResourceMgt/WEB-INF/index.jsp **。實際上,頁面不在WebContent文件夾中的WEB-INF文件夾中。所以請建議我如何在那裏指定自定義jsp文件夾路徑。 – 2012-04-07 11:58:14

+0

請在您的問題的描述中包含Spring的''ViewResolver''的bean配置。您可以使用此[參考](http://static.springsource.org/spring/docs/2.5.x/reference/view.html)進行自定義JSP文件夾配置。 – nobeh 2012-04-07 12:08:34

+1

只需更改/ WEB-INF/jsps至/ – 2012-04-07 12:11:12