又是异常`~~郁闷~! 求教~~~`

yan55667 2008-03-28 07:23:02
1.
我在一个JSP里嵌套另一个JSP页面 如下: display参数是传的JSP
<jsp:include page="${param.display}" flush="true"/>
运行后出现异常 但不影响程序正常操作
java.lang.StringIndexOutOfBoundsException: String index out of range: -1

2.
过滤器里页面跳转
request.getRequestDispatcher("index.jsp?display=Picture.jsp").forwar(request,response);
异常
java.lang.IllegalStateException: Cannot forward after response has been committed

改成Response后
((HttpServletResponse)Response).sendRedirect("Login.jsp");
没有异常 显示空白页~~

应该说的够清楚了吧~~~~
很郁闷~`求高手解
...全文
262 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
yan55667 2008-04-05
  • 打赏
  • 举报
回复
谢谢各位帮助
不想了 大不了重写一遍
yan55667 2008-04-02
  • 打赏
  • 举报
回复
用request.getRequestDispatcher("index.jsp?display=Picture.jsp").forward(request,response);
会出现异常
java.lang.IllegalStateException: Cannot forward after response has been committed
这个异常会不会是因为我嵌套页面的关系

想不通·~
请问还有没有别的页面跳转的办法

yan55667 2008-04-02
  • 打赏
  • 举报
回复
但是看14楼的代码
我确实只转交了一次
ee4456 2008-04-02
  • 打赏
  • 举报
回复
java.lang.IllegalStateException: Cannot forward after response has been committed
反正这个异常可能是转发了2次造成的
yan55667 2008-04-01
  • 打赏
  • 举报
回复
谢谢提醒~``

我把这句话复制到记事本上后 他在forward后换行了
我又 <- 一下想弄成一行 没注意删掉了d
我....
jone33 2008-04-01
  • 打赏
  • 举报
回复
request.getRequestDispatcher("index.jsp?display=Picture.jsp").forwar(request,response);
你太牛了,大哥,forward 给你一个介意,写程序时请细心 心细 再心细
yan55667 2008-04-01
  • 打赏
  • 举报
回复
JSP没有问题
页面跳转只是在filter里跳不过去
在普通servlet里和jsp里都可以跳转的
keke_bear 2008-04-01
  • 打赏
  • 举报
回复
((HttpServletResponse)Response).sendRedirect("Login.jsp");
没有异常 显示空白页~~

空白页的问题,我以前页遇到过,没有异常,开始认为是struts-config.xml的问题,后来发现是转发到的页面有问题。你看一下是不是Login.jsp的问题啊
joseph1985 2008-04-01
  • 打赏
  • 举报
回复
很有趣..
l_wenb 2008-04-01
  • 打赏
  • 举报
回复
up
ee4456 2008-04-01
  • 打赏
  • 举报
回复
((HttpServletResponse)response).sendRedirect("index.jsp?display=Picture.jsp");
是这块有错误吧。。你都sendRedirect了,那么request 里的对象肯定都没。我觉得这些有问题。。
再一个,没有必要在前边再加个强制转换response,我觉得还是不要用sendRedirect,用forward试试吧
yan55667 2008-03-31
  • 打赏
  • 举报
回复
谢谢楼上几位朋友~

但是在servlet里我好象没有用out去写东西
LS是怎么解决的


<jsp:include page="${param.display}" flush="true"/>
这个我一开始运行的不是这个页面
我一开始运行的是login.jsp 运行起来后就出错了
登陆后才转交到index.jsp?display=pricture.jsp
如果要一开始就给传值 我不知道该怎么传

这种嵌套我在另一个程序中用过 一模一样的用法
但那个不知道怎么就没错
ee4456 2008-03-31
  • 打赏
  • 举报
回复
java.lang.IllegalStateException: Cannot forward after response has been committed
这个可能是你用out对象写了东西后flush,造成的。这个我曾经碰到过。。。

第一个问题,param本身他就是个array形式的,造成这个问题有可能是哪个直没有接到吧。。
我是这么考虑的,不知道对你有帮助没。

zhsjun 2008-03-31
  • 打赏
  • 举报
回复
param是el的内部对象,说明你没有传递display这个参数,你可以在你的地址中增加?display=picture.jsp
yan55667 2008-03-31
  • 打赏
  • 举报
回复
to 千里冰封
运行后的错误提示指定的是嵌套这一行
<jsp:include page="${param.display}" flush="true"/>
而我把page="picture.jsp"写死后就没有错了
所以才很郁闷,这个标签难道也会有字符串的下标越界异常吗
yan55667 2008-03-31
  • 打赏
  • 举报
回复
to 12.
package com.supermarket.filter;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.supermarket.vo.UserBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BuyFilter extends HttpServlet implements Filter {
private FilterConfig filterConfig;
//Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}

//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) {
try {
UserBean ub = (UserBean) ((HttpServletRequest) request).getSession().
getAttribute("login");
if (ub == null) {
System.out.println("buynull");
((HttpServletResponse)response).sendRedirect("Login.jsp");
} else if (!ub.getType().equals("采购员") &&!ub.getType().equals("超级管理员")) {
System.out.println("buyquanxian");
((HttpServletResponse)response).sendRedirect("index.jsp?display=Picture.jsp");
} else {
System.out.println("buyok");
filterChain.doFilter(request, response);
}
} catch (IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
} catch (ServletException ex) {
ex.printStackTrace();
}

}

//Clean up resources
public void destroy() {
}
}

我所有的跳转语句都用if(){}else{}隔开了
千里冰封820 2008-03-30
  • 打赏
  • 举报
回复
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
字符串的下标越界异常,你的代码再仔细检查一下
胡矣 2008-03-30
  • 打赏
  • 举报
回复
Cannot forward after response has been committed

应该是你在
request.getRequestDispatcher("index.jsp?display=Picture.jsp").forwar(request,response);
前面已经执行过跳转...请确认...
yan55667 2008-03-29
  • 打赏
  • 举报
回复
晕~~
我想问的是异常~~
拜托~
回答问题专心点~
qsrock 2008-03-29
  • 打赏
  • 举报
回复
晕,用eclise写就不会出现这样的问题了
加载更多回复(9)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧