PDA

View Full Version : Help on java servlet and jsp


Chithra
09-10-2008, 03:50 AM
Hi Am designing a login page and i have got the following exception

"Sep 9, 2008 9:35:55 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.5.0_12\jre\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.5.0_12\bin\..\jre\bin\client;C:\Program Files\Java\jdk1.5.0_12\bin\..\jre\bin;PATH=C:\PROGRA~1\Borland\CBUILD~1\Projects\Bpl;C:\PROGRA~1\Bor land\CBUILD~1\Bin;C:\Program Files\Java\jdk1.5.0_12\bin;C:\PROGRAM FILES\THINKPAD\UTILITIES;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\ATI Technologies\ATI Control Panel;C:\Windows\System32;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\Program Files\Symantec\pcAnywhere\;C:\Sun\SDK\bin;C:\Sun\SDK\bin;??
Sep 9, 2008 9:35:55 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Sep 9, 2008 9:35:55 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1246 ms
Sep 9, 2008 9:35:56 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Sep 9, 2008 9:35:56 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.25
Sep 9, 2008 9:35:56 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Sep 9, 2008 9:35:56 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive beerV1.war
Sep 9, 2008 9:35:57 PM org.apache.catalina.core.ApplicationContext log
INFO: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
Sep 9, 2008 9:35:57 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Sep 9, 2008 9:35:57 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Sep 9, 2008 9:35:57 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Sep 9, 2008 9:35:57 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Sep 9, 2008 9:35:58 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Sep 9, 2008 9:35:58 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Sep 9, 2008 9:35:58 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/80 config=null
Sep 9, 2008 9:35:58 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Sep 9, 2008 9:35:59 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3241 ms
from databasesdfdsaf
dsfdsaf
chithu3383
password123*
from databasechithu3383
password123*
chithu3383
password123*
Hai ur userd id and pwd is present
Sep 9, 2008 9:36:35 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Login threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:433)
at com.home.login.LoginServlet.doPost(LoginServlet.java:55)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:595)
"




My code is here: This is the servlet called when submit is cliked.

package com.home.login;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet {
Hashtable users=new Hashtable();
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException{
doPost(request,response);
}

public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException{
String userid = request.getParameter("UserName");
String password=request.getParameter("password");
//PreparedStatement ps=null;
Statement stmt=null;
Connection con=null;
ResultSet rs=null;

try {
Class.forName("com.hxtt.sql.access.AccessDriver").newInstance();

//Please see Connecting to the Database section of Chapter 2. Installation in Development Document
//Please change "demodata" to your database directory
String url = "jdbc:Access:///D:/Documents and Settings/subramanic/My Documents/newuser.mdb";

//Please replace with your query statement.
//You should read SQL syntax in HXTT Access Development Document
String sql = "select userid,password from Nuser1";
con = DriverManager.getConnection(url);
stmt=con.createStatement();
rs = stmt.executeQuery(sql);
String uid=null,pwd=null;
while (rs.next()) {
uid=rs.getString("userid");
pwd=rs.getString("password");
System.out.println("from database"+uid);
System.out.println(pwd);
System.out.println(userid);
System.out.println(password);
if((uid!=null)&& (pwd!=null)){
if((uid.equalsIgnoreCase(userid))&& (pwd.equals(password))){
System.out.println("Hai ur userd id and pwd is present");
response.sendRedirect("D:/WORKSPACE/HomeExpense/mypage.jsp");
}else {
response.sendRedirect("/HomeExpense/Login.html");
}
}

}



}catch (SQLException e) {
throw new ServletException(e);
} catch (ClassNotFoundException e) {
throw new ServletException(e);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} finally {
try {

if(stmt != null)
stmt.close();
if(rs != null)
rs.close();
if(con != null)
con.close();
} catch (SQLException e) {}
}
}

}


Can any one help me solve this exception, i have tried many options but could not solve this error.

Thanks in advance.
Chithra

shyam
09-12-2008, 12:55 PM
..
public class LoginServlet extends HttpServlet {
Hashtable users=new Hashtable();
...

public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException{

...
if((uid!=null)&& (pwd!=null)){
if((uid.equalsIgnoreCase(userid))&& (pwd.equals(password))){
System.out.println("Hai ur userd id and pwd is present");
response.sendRedirect("D:/WORKSPACE/HomeExpense/mypage.jsp");
}else {
response.sendRedirect("/HomeExpense/Login.html");
}
...

}

you cannot redirect to any arbitrary location in your computer :O...you can redirect to any valid http url. all you need to do is chang the redirect to

response.sendRedirect("mypage.jsp");

ghmd86
11-15-2011, 02:20 PM
hi i think this problem is due to giving the response.redirect under second if block if you give it in first if block you might get the correct result