• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JSP,JDBC

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any one point out what's wrong with this code???
 
Pradyumna Sahoo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the jsp page
 
Pradyumna Sahoo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem is the code with is that , It is only retrieving only the 1st column of the database.

Below is the run time error
---------------------------------------------------------------------------------------------------------
Connecting
[email protected]
Amit
Kumar
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:349)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at com.anthem.Login.doPost(Login.java:65)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
----------------------------------------------------------------------------------------------------------------------------------
 
Ranch Hand
Posts: 439
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Pradyumna Sahoo,

Am afraid the call to requestDispatcher is the reason why it is giving the illegalStateException. After this call , the response has been commited and you cannot make further changes to the response object . See the stack trace

The exception is thrown when the response object is again asked to set attributes .


Now as far as your scenario is concerned , I think you would be better off by populating a List of entites for each of the row present in the resultset and then set this list into the session instead of individual Strings of email, name etc.

Then on the JSP , you can simply iterate over this array using JSTL foreach .
 
Pradyumna Sahoo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks sir.
 
Pradyumna Sahoo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to JSP. can you please explain the whole process??
 
Ranch Hand
Posts: 63
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you use where clause for email and passWord ?
you can use sendRedirect() also.
 
Saif Asif
Ranch Hand
Posts: 439
Hibernate Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure.

Well for a start , it is important that you understand the purpose of a JSP . A JSP is there to provide dynamic web pages to your application . It is comprised of basic HTML tags with java code snippets embedded in between . When you open a jsp ( via a servlet and jsp container server e.g tomcat ) , the tomcat first compiles the JSP to a relevant bytecode and then replaces the java code snippets with calculated ( generated ) values and then renders the final HTML page to display on the browser.

The life cycle ( in a very concise manner ) will be that when you deploy the JSP on a server, it is there on the server as a JSP ( unless you specify it to compile on load ) . After your first hit to this JSP , the servlet container compiles the JSP and generates the class file , this is then used to evaluate the java code snippets inside the JSP and mixed with HTML tags , the final page is rendered on to the browser. Now for all consecutive hits , the JSP will not be re-compiled ( this means that the first hit will be relatively slow ) .

Now JSPs are used in a number of ways .
1) code in JSP method :- In this method you put your entire code inside the JSP along with the HTML tags . No separaete java files are required since the JSP has all the necessary java code inside it . This is NOT a preferred way .

2) MVC :- In this architecture , the JSP is used just a view port , to display final results on the browser. Some java code snippets are still present in this JSP but the main business logic is coded inside a separate Java file . The java file and the relative JSP are then linked via the framework . I can give you the example of Struts2, in which a configuration file ( struts.xml ) is where all the java classes are 'mapped' to their reltive JSP files. This is the most preferred way of using JSPs
 
Pradyumna Sahoo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sir thanks for tour insight . Can you explain to me , how to upload a file form a JSP page to a database. Appreciate your help.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should not be going directly from the JSP to the database. You need to have a servlet in between to handle the file upload stuff and use an API like Apache Commons.
Here is one such discussion.
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic