aspose file tools*
The moose likes JSP and the fly likes JSP,JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP,JDBC " Watch "JSP,JDBC " New topic
Author

JSP,JDBC

Pradyumna Sahoo
Greenhorn

Joined: Feb 27, 2013
Posts: 22
Can any one point out what's wrong with this code???
Pradyumna Sahoo
Greenhorn

Joined: Feb 27, 2013
Posts: 22
here is the jsp page
Pradyumna Sahoo
Greenhorn

Joined: Feb 27, 2013
Posts: 22
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
amit_kumar@gmail.com
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)
----------------------------------------------------------------------------------------------------------------------------------
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

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 .


Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Pradyumna Sahoo
Greenhorn

Joined: Feb 27, 2013
Posts: 22
Thanks sir.
Pradyumna Sahoo
Greenhorn

Joined: Feb 27, 2013
Posts: 22
I am new to JSP. can you please explain the whole process??
Niraj Jha
Ranch Hand

Joined: Feb 20, 2013
Posts: 63

Why don't you use where clause for email and passWord ?
you can use sendRedirect() also.
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

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

Joined: Feb 27, 2013
Posts: 22
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.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

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.


SCJP, SCWCD.
|Asking Good Questions|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP,JDBC