Results 1 to 6 of 6
  1. #1
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

    Default parseInt in servlets{solved}

    im trying to parse int a request from a form "a user id"

    Java Code:
        	id = Integer.parseInt((request.getParameter("id")));
    but im receiving exception
    Java Code:
       org.apache.jasper.JasperException: java.lang.Integer cannot be cast to java.lang.String
    thanks
    miki

    UPDATE:
    the mistake was on another jsp.....
    Last edited by miko5054; 10-29-2010 at 09:51 PM.

  2. #2
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    Hi miki,

    What is the type of id left of the equals sign? And what kind of type does request.getParameter("id") return?

    Erik

  3. #3
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

    Default

    int id; // id is int

    and the requset is String according to the servlets api...

  4. #4
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    Are you sure the problem is in the quoted line then? Maybe you could post some more source code?

  5. #5
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

    Default

    this is the servlet

    Java Code:
      import il.co.mbank.actions.AdminActions;
    import il.co.mbank.exceptions.MBankException;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    import mBank.MBank;
    
    public class Login extends HttpServlet {
    	private static final long serialVersionUID = 1L;
    
    	public Login() {
    
    	}
    
    	protected void doGet(HttpServletRequest request,
    			HttpServletResponse response) throws ServletException, IOException {
    		doPost(request, response);
    	}
    
    	protected void doPost(HttpServletRequest request,
    			HttpServletResponse response) throws ServletException, IOException {
    		AdminActions adminActions = new AdminActions();
    		MBank bank = null;
    
    		try {
    			bank = new MBank();
    		} catch (MBankException e2) {
    			// TODO Auto-generated catch block
    			e2.printStackTrace();
    		}
    
    		String ids = request.getParameter("id");
    		int id = Integer.parseInt((ids));
    		String password = request.getParameter("password");
    
    		// validate id and password ...
    		System.out.println("*****id=" + id + "*****");
    		System.out.println("*****password=" + password + "*****");
    		// TODO
    
    //		 if (!Utils.isNumeric(id)) {
    //		 response.sendRedirect("errors/login_error.jsp");
    //		 return;
    //		 } else
    		try {
    
    			if (adminActions.checkLoginAdmin(password, id)) {
    				HttpSession session = request.getSession(true);
    				session.setAttribute("id", id);
    				// getServletContext().getRequestDispatcher("/admin.jsp").forward(request,
    				// response);
    				response.sendRedirect("admin.jsp");
    			} else if (bank.checkLogin(id, password)) {
    
    				HttpSession session = request.getSession(true);
    				session.setAttribute("id", id);
    				response.sendRedirect("client.jsp");
    			} else {
    				response.sendRedirect("errors/login_error.jsp");
    			}
    		} catch (MBankException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    	}
    
    	{
    
    	}
    
    }


    stack trace
    Java Code:
     29/10/2010 20:51:51 org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    	at org.apache.jsp.admin_jsp._jspService(admin_jsp.java:52)
    	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    	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.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    	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:174)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.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:636)

  6. #6
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    Hi Miki,

    Has the problem been solved then (according to your update on you initial post)?

    If so, alter the title of this thread to start with [SOLVED]. I think there is an option in the thread menu for that.

    Erik

Similar Threads

  1. parseInt
    By trefoil in forum New To Java
    Replies: 4
    Last Post: 09-09-2009, 08:12 PM
  2. ParseInt question
    By McChill in forum New To Java
    Replies: 1
    Last Post: 03-09-2009, 10:34 PM
  3. parseInt() vs. intValue()
    By JavaPilot in forum New To Java
    Replies: 5
    Last Post: 02-04-2009, 09:39 AM
  4. Integer.parseInt?
    By Exhonour in forum New To Java
    Replies: 4
    Last Post: 01-20-2009, 03:31 AM
  5. Problem with Integer.parseInt()
    By Hevonen in forum New To Java
    Replies: 2
    Last Post: 12-14-2008, 04:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •