Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

submitting and forwarding JSP pages with beans  RSS feed

 
Lavanya Halliwell
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a bit confused as to why i'm getting this error. I have a JSP page which on submitting a bean should be storing the values in the bean and then forwarding the page to a second JSP for information processing. The strange thing is that I have other JSPs just like this one that don't give this error, even work just fine.

JSP code:


Error: (get this after I click submit and instead of forwarding it tries to print the form again, form has 2 date pickers, and 3 dropdown lists, the last 2 dropdown lists don't display after submit....nor the submit button)

Servlet.service() for servlet jsp threw exceptionjava.lang.IllegalStateException: Error: Attempt to clear a buffer that's already been flushed at org.apache.jasper.runtime.PageContextImpl.doForward (PageContextImpl.java:653) at org.apache.jasper.runtime.PageContextImpl.forward(P ageContextImpl.java:642) at org.apache.jsp.pages.content.detailreport.detailrep ort_jsp._jspService(detailreport_jsp.java:215) at org.apache.jasper.runtime.HttpJspBase.service(HttpJ spBase.java:105) at javax.servlet.http.HttpServlet.service(HttpServlet. java:860) at org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:336) at org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:297) at org.apache.jasper.servlet.JspServlet.service(JspSer vlet.java:247) at javax.servlet.http.HttpServlet.service(HttpServlet. java:860) at sun.reflect.GeneratedMethodAccessor57.invoke(Unknow n Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Del egatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.security.SecurityUtil$1.run(Sec urityUtil.java:249) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAsPrivileged(Subject. java:517) at org.apache.catalina.security.SecurityUtil.execute(S ecurityUtil.java:282) at org.apache.catalina.security.SecurityUtil.doAsPrivi lege(SecurityUtil.java:165) at org.apache.catalina.core.ApplicationFilterChain.int ernalDoFilter(ApplicationFilterChain.java:257) at org.apache.catalina.core.ApplicationFilterChain.acc ess$000(ApplicationFilterChain.java:55) at org.apache.catalina.core.ApplicationFilterChain$1.r un(ApplicationFilterChain.java:161) at java.security.AccessController.doPrivileged(Native Method) at org.apache.catalina.core.ApplicationFilterChain.doF ilter(ApplicationFilterChain.java:157) at org.apache.catalina.core.StandardWrapperValve.invok e(StandardWrapperValve.java:263) at org.apache.catalina.core.StandardPipeline.invoke(St andardPipeline.java:551) at org.apache.catalina.core.StandardContextValve.invok eInternal(StandardContextValve.java:225) at org.apache.catalina.core.StandardContextValve.invok e(StandardContextValve.java:173) at org.apache.catalina.core.StandardPipeline.invoke(St andardPipeline.java:551) at org.apache.catalina.core.StandardHostValve.invoke(S tandardHostValve.java:170) at org.apache.catalina.core.StandardPipeline.invoke(St andardPipeline.java:551) at org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:132) at org.apache.catalina.core.StandardPipeline.invoke(St andardPipeline.java:551) at org.apache.catalina.core.ContainerBase.invoke(Conta inerBase.java:933) at org.apache.coyote.tomcat5.CoyoteAdapter.service(Coy oteAdapter.java:189) at com.sun.enterprise.web.connector.grizzly.ProcessorT ask.doProcess(ProcessorTask.java:604) at com.sun.enterprise.web.connector.grizzly.ProcessorT ask.process(ProcessorTask.java:475) at com.sun.enterprise.web.connector.grizzly.ReadTask.e xecuteProcessorTask(ReadTask.java:371) at com.sun.enterprise.web.connector.grizzly.ReadTask.d oTask(ReadTask.java:264) at com.sun.enterprise.web.connector.grizzly.TaskBase.r un(TaskBase.java:281) at com.sun.enterprise.web.connector.grizzly.WorkerThre ad.run(WorkerThread.java:83)Caused by: java.io.IOException: Error: Attempt to clear a buffer that's already been flushed at org.apache.jasper.runtime.JspWriterImpl.clear(JspWr iterImpl.java:168) at org.apache.jasper.runtime.PageContextImpl.doForward (PageContextImpl.java:651) ... 38 more

Diagnostic Causes


Diagnostic Checks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is your code not properly indented?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't have any Java code in a JSP. Refactor all the code to servlets or other Java classes.

The specific problem is that you cannot forward once output has been sent as the response.

You might find this article on how to properly structure web applications helpful.
 
Lavanya Halliwell
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so if I take the code out of the file, and stick to 1 form which upon submit via javascript. I don't get the last error, but on the "forwarded" page, the bean values are null. Is there any way to make sure the form is actually submitting the values?
The names of html components are the same as that in the bean, and I have created the getters and setteres, and still get nulls.



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not clear why you are forwarding at all.
 
Lavanya Halliwell
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my goal is to use the form results and on the next page dynamically create a query to

1. display on the page.

2. add the export to excel feature so that I can save the table data.

is why I created a session bean, but for some reason, unlike my other JSPs that are really similar, the bean attributes turn out null after I submit the form.

so for this it we really don't care how the bean is to be used, but why the data isn't getting stored.

in another program, I had like 7 different beans, and I made then "session" so I could use them later.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still not clear what the flow of the data is. Did you read the article I linked to? The flow should be:
  • The form is displayed to user.
  • User enters data on form and clicks Submit button.
  • The form data is submitted to a servlet (never to a JSP) for processing.
  • Servlet delegates to busines layer to perform whatever job it needs to do.
  • Servlet then redirects to the page controller for whatever page is to be displayed next.
  • The page controller performs any data grathering necessary to display its page. This data is placed in request scope.
  • Page controller forwards to JSP for view.

  • It doesn't seem like your data flow follows this pattern.
     
    Lavanya Halliwell
    Ranch Hand
    Posts: 57
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i managed to rework/clean up my JSPs, and organize them so I knew exactly which bean was used and were it was used. Need to start of like this in the first place.

    thanks again for pointing me toward that website!
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 66205
    151
    IntelliJ IDE Java jQuery Mac Mac OS X
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!