0

有一个类,X.Java.如下两行,我正在做

request.getSession.setAttribute("count",String.valueOf(rsp.getCount()));

在上面我从数据库中获取计数rsp.getCount()。这getcount()是整数类型,我将更改为 String asString.valueOf(rsp.getCount()并设置为一个属性 as count

有一个 JSP 作为 X.jsp 现在我正在使用getAttribute并将值存储在类型failCount变量中string

String failCount = request.getSession.getAttribute("count");

现在我想将此值转换为整数类型,因为我写了这一行

int countInt = Integer.parseInt(failCount);

我收到如下错误

127039 13-02-26 17:13:35 ERROR http-10.18.2.105-12205-Processor4 - <JSPFilter ServletException> - test.abc.common.filter.JSPFilter.doFilter(JSPFilter.java:111) 
org.apache.jasper.JasperException: Exception in JSP: abc/x.jsp:66 

63:              
64:          } 
65:          String failCount = (String)request.getSession().getAttribute("failCount"); 
66:          int failCountint = Integer.parseInt(failCount); 
67:          //System.out.println(failCountint); 
68:           
69:           


Stacktrace: 
        at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:489) 
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411) 
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308) 
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259) 
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) 
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) 
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679) 
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461) 
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:399) 
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301) 
        at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:142) 
        at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:247) 
        at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1105) 
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:841) 
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:755) 
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396) 
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350) 
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:627) 
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

请帮我解决这个问题。

4

3 回答 3

0

我认为 failCount 是 null 那为什么 int failCountint = Integer.parseInt(failCount);

所以请使用 System.out.println(failCount);

并且还在错误行周围使用 try catch 块。

于 2013-02-26T12:21:48.587 回答
0

确保您在 HttpRequest 中设置会话

request.getSession.setAttribute("count",String.valueOf(rsp.getCount()));

这个java文件是servlet吗,那么它会很好用。

还要确保 rsp.getCount() 不返回“null”。

在 JSP 文件中

String failCount = (String)request.getSession().getAttribute("failCount"); 
int failCountint = Integer.parseInt(failCount); 

你为什么使用 request.getSession() 而不是 session,并且你试图获取 failcount 而不是 count

尝试这个

String failCount = session.getAttribute("count").toString();
int countInt = Integer.parseInt(failCount);

我认为这可能有助于全面...

于 2013-02-26T12:14:22.243 回答
0

设置值为会话:

request.getSession.setAttribute("count",String.valueOf(rsp.getCount()));

从会话中读取值:

String failCount = (String)request.getSession().getAttribute("failCount"); 

在会话中设置值时,您正在调用它count,而在从 JSP 读取值时,您正在调用它failCount

于 2013-02-26T12:14:31.597 回答