Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2010
    Location
    Serbia
    Posts
    4
    Rep Power
    0

    Default Sending data trough for to two JSP pages

    Hi!
    Im new to this forum, and I already used it for some tips and tricks. Thank you all for that. Now I have a two problems, and hope you can help me as many time before.

    Im working on my graduate work, and its web application for keeping business books for small stores.
    I've generated trough PowerDesigner my class diagram and generated MySQL code which helped me to create my database.

    Problem 1st:

    I have jsp page that serves for data input.
    That jsp page contains use bean and form that sends data to another, "save" page. On that page, I create new object and with request.getParameter I take data and with setSomething I put my data into the table. It works. But problem is that I need to put same data in some other table too. And doing same, it just doesnt work!

    I would put my error message here, but. ..

    Problem 2nd:

    Yesterday it worked. I can see data I saved throw MySQL Query Browser.
    Today - not working. So it must be logical mistake...

    same page, not inserting into any page!

    PAGE FOR INPUT:


    Java Code:
    <%@page contentType="text/html; charset=UTF-8"  import="model.*" %>
    <%@page import="java.util.List"%><html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here </title>
    </head>
    <body>
    
    <jsp:useBean class="model.Kb48302Tekuciracun" id="tekuciracun" scope="session"/>
    
    <form name="tekuciracun" style="height: 194px" method="post" action="../save/sacuvajTekuciRacun.jsp">
    
    <tr>
    				<td>Opis promene: </td>
    				<td><input type="text" name="opispromene"></td>
    			</tr>
    			<tr>
    				<td>Iznos uplate: </td>
    				<td><input type="text" name="iznosuplate"></td>
    			</tr>
    			<tr>
    				<td>Iznos isplate: </td>
    				<td><input type="text" name="iznosisplate"></td>
    			</tr>
    			<tr>
    				<td>Upis u trgovačku knjigu? </td>
    				<td><select name="comboTK">
    				<option value="prazno">&nbsp;</option>
    				<option value="da">DA</option>
    				<option value="ne" selected="selected">NE</option>
    				</select> </td>
    			</tr>
    etc...

    Page where I go to save data:


    Java Code:
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     			<%@page import="model.*, java.util.*, java.util.Date, java.text.*" contentType="text/html; charset=UTF-8"%> 
    
    Kb48302Tekuciracun noviTekuciRacun = new Kb48302Tekuciracun(); 
    
    String opis = request.getParameter("opispromene");
    		        noviTekuciRacun.setOpispromene(opis);
    		        
    		    String uplata = request.getParameter("iznosuplate");
    		    Double uplataDouble = Double.parseDouble("uplata");
    		        noviTekuciRacun.setIznosuplate(uplataDouble);
    		        
    		    String isplata = request.getParameter("iznosisplate");
    		    Double isplataDouble = Double.parseDouble("isplata");
    		        noviTekuciRacun.setIznosisplate(isplataDouble);
    etc...

    I know its a bit hard for reading because you dont know my language... :S

    My exception..
    .

    exception

    Java Code:
    org.apache.jasper.JasperException: An exception occurred processing JSP page /save/sacuvajTekuciRacun.jsp at line 46
    
    43: 		        noviTekuciRacun.setOpispromene(opis);
    44: 		        
    45: 		    String uplata = request.getParameter("iznosuplate");
    46: 		    Double uplataDouble = Double.parseDouble("uplata");
    47: 		        noviTekuciRacun.setIznosuplate(uplataDouble);
    48: 		        
    49: 		    String isplata = request.getParameter("iznosisplate");
    
    
    Stacktrace:
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause
    
    java.lang.NumberFormatException: For input string: "uplata"
    	sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
    	java.lang.Double.parseDouble(Unknown Source)
    	org.apache.jsp.save.sacuvajTekuciRacun_jsp._jspService(sacuvajTekuciRacun_jsp.java:103)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
    what Im doing wrong? Convertion?
    Thanks in advance!
    Last edited by katarina.the.great; 09-03-2010 at 04:49 PM.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    In this case, this error is because you are reading a string literal of the variable name "uplata", instead of the variable name uplata.

    For example, change line 46 to be this: (remove the quotes around uplata)
    Java Code:
    45: String uplata = request.getParameter("iznosuplate");
    46: Double uplataDouble = Double.parseDouble(uplata);
    the problem is because Double.parseDouble( ) method expects the String argument to be a string representation of a numerical quantity.

    Another related problem might come up later, since you are reading the value a user entered into the HTML form field, it is possible they might enter something that does not parse into a double value, for example, "asdfasdfasdf",

    in this case, it is likely possible to handle this by surrounding the parseDouble() inside a try.. catch block, such as

    Java Code:
    Double uplataDouble = null;
    
    String uplata = request.getParameter("iznosuplate");
     try {
       uplataDouble = Double.parseDouble(uplata);
      }
      catch (NumberFormatException ex) {
        // was not able to parse the input string into a double
      }
    
      if (uplataDouble != null) {
        noviTekuciRacun.setIznosuplate(uplataDouble);
      }
      else {
        // here is where we might do some error handling, 
        // such as setting an error message onto the request parameter
        // and returning to the input form page.
      }

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,010
    Rep Power
    20

    Default

    Why do people insist on doing this stuff in a JSP?

    Do the training courses (or classes) no longer start with Servlets?

  4. #4
    Join Date
    Sep 2010
    Location
    Serbia
    Posts
    4
    Rep Power
    0

    Default

    yes, I was stucked with this line:
    Double uplataDouble = Double.parseDouble("uplata");
    because I shouldnt put quote marks... stupid me.

    But now, when I try to put my data into another table too,
    I get null pointer exception :(

    Toll, it's because my class, I have to do it this way :S


    ok, look at this now:
    Java Code:
    [B]String stringTK_upis = request.getParameter("comboTK");
    noviTekuciRacun.setTkupis(stringTK_upis);
    if (stringTK_upis.equalsIgnoreCase("da")){
       
        	Kb48302Trgovackaknjiga novaTK = new Kb48302Trgovackaknjiga();
        	
        	Kb48302TrgovackaknjigaId tkID = new Kb48302TrgovackaknjigaId();
    		tkID.setBrojdokumenta("brojizvoda");
        		tkID.setRjSifraprodavnice("sifraprodavnice");
        		tkID.setTipdokumenta("izvod");
    		    		
    	novaTK.setId(tkID);
    	novaTK.setDatumuplatepazara(datum);
    	novaTK.setIznosuplate(uplataDouble);
    	novaTK.setKb48302Radnajedinica(prodavnica);
    		    		novaTK.setKb48302Sifarnikdokumenata(Controler.getDokumentaByNaziv(tkID.getTipdokumenta()));
    	novaTK.setRazduzenjeprodavnice(uplataDouble);
    	novaTK.setZaduzenjeprodavnice(isplataDouble);
    		    		
    	okTK = Controler.sacuvajTK(novaTK);
    		 
    		    		
    }[/B]
    where sacuvajTK from Controler looks like this:

    Java Code:
    public static boolean sacuvajTK(Kb48302Trgovackaknjiga tk){
    			try{		
    				beginTransaction();
    				Session s=getSession();
    				s.saveOrUpdate(tk);
    				commitTransaction();
    				closeSession();
    				return true;
    			}catch(Exception e){
    				e.printStackTrace();
    				return false;
    			}
    		}



    of course, I always catch exception :(

    my error stack... :(
    Java Code:
    [B]java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    	at java.util.ArrayList.RangeCheck(Unknown Source)
    	at java.util.ArrayList.get(Unknown Source)
    	at model.Controler.getDokumentaByNaziv(Controler.java:1106)
    	at org.apache.jsp.save.sacuvajTekuciRacun_jsp._jspService(sacuvajTekuciRacun_jsp.java:126)
    	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    	at java.lang.Thread.run(Unknown Source)
    java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
    	at org.hibernate.type.IntegerType.set(IntegerType.java:64)
    	at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
    	at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
    	at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:307)
    	at org.hibernate.persister.entity.AbstractEntityPersister.getDatabaseSnapshot(AbstractEntityPersister.java:1046)
    	at org.hibernate.engine.StatefulPersistenceContext.getDatabaseSnapshot(StatefulPersistenceContext.java:269)
    	at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:212)
    	at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:535)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:103)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    	at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)
    	at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:526)
    	at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:522)
    	at model.Controler.sacuvajTK(Controler.java:217)
    	at org.apache.jsp.save.sacuvajTekuciRacun_jsp._jspService(sacuvajTekuciRacun_jsp.java:130)
    	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    	at java.lang.Thread.run(Unknown Source)[/B]
    is there the end of this :((
    Last edited by katarina.the.great; 09-03-2010 at 04:51 PM.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,010
    Rep Power
    20

    Default

    I do despair about the state of training courses/classes these days.
    JSPs are not the place to be doing things like this and will only create bad habits.

    Oh well, not your fault...

    Anyway, when posting code you need to really use code tags (like travis has above) to maintain formatting. That aside, where is this line of code "at model.Controler.getDokumentaByNaziv(Controler.java :1106)" ?

    That's where your array index problem is. The array on that line is empty, and the code is trying to access the (non-existent) first element...0.

  6. #6
    Join Date
    Sep 2010
    Location
    Serbia
    Posts
    4
    Rep Power
    0

    Default

    okay, I have this:

    Java Code:
    tkID.setTipdokumenta("izvod");
    ...
    Kb48302Sifarnikdokumenata izvod =Controler.getDokumentaByNaziv(tkID.getTipdokumenta());
    novaTK.setKb48302Sifarnikdokumenata(izvod);
    and in Controller I have:

    Java Code:
    public static Kb48302Sifarnikdokumenata getDokumentaByNaziv(String vrstadokumenta){
    			try{
    				beginTransaction();
    				Session s = getSession();
    				Query q = s.createQuery("from Kb48302Sifarnikdokumenata a where 
                                                                    a.vrstadokumenta=:vrstadokumenta");
    				q.setString("vrstadokumenta", vrstadokumenta);
    				List l = q.list();
    				Kb48302Sifarnikdokumenata dok= (Kb48302Sifarnikdokumenata)l.get(0);
    				commitTransaction();
    				closeSession();
    				return dok; 
    			}catch(Exception e){
    				e.printStackTrace();
    				return null;
    			}
    			
    		}

    I do this because its not always "izvod" it can be other things too, but those values are already in table Kb48302Sifarnikdokumenata... I put it like string in this case just to be sure there is something in this array, but it looks like I just cannot recognize it... :(

    thank you very much, you are very helpful!

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,010
    Rep Power
    20

    Default

    I'm guessing that query returns nothing, so the l.get(0) gives an array index error?
    I'd suggest checking if anything is there first.

  8. #8
    Join Date
    Sep 2010
    Location
    Serbia
    Posts
    4
    Rep Power
    0

    Default

    Thanks for telling me obvious Tolls! I was sure it wasnt empty because I striclty put it as "izvod", but when I checked it, "izvod" wasnt there!!

    anyway, I still have that
    Java Code:
    java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
    error from up (after that array error) which is totally not reasonable to me because I dont use Integer at all... in both classes...

    Java Code:
    public class Kb48302Trgovackaknjiga implements java.io.Serializable {
    
    	private Kb48302TrgovackaknjigaId id;
    	private Kb48302Radnajedinica kb48302Radnajedinica;
    	private Kb48302Sifarnikdokumenata kb48302Sifarnikdokumenata;
    	private Double zaduzenjeprodavnice;
    	private Double razduzenjeprodavnice;
    	private Date datumuplatepazara;
    	private Double iznosuplate;
    Java Code:
    public class Kb48302TrgovackaknjigaId implements java.io.Serializable {
    
    	private String brojdokumenta;
    	private String rjSifraprodavnice;
    	private String tipdokumenta;
    Java Code:
    public class Kb48302TekuciracunId implements java.io.Serializable {
    
    	private String rjSifraprodavnice;
    	private String brojizvoda;
    Java Code:
    public class Kb48302Tekuciracun implements java.io.Serializable {
    
    	private Kb48302TekuciracunId id;
    	private Kb48302Radnajedinica kb48302Radnajedinica;
    	private Kb48302Sifarnikbanaka kb48302Sifarnikbanaka;
    	private Kb48302Poslovnipartneri kb48302Poslovnipartneri;
    	private Date datumizvoda;
    	private String opispromene;
    	private Double iznosuplate;
    	private Double iznosisplate;
    	private String tkupis;
    	private String rashodiupis;
    I really owe you a chocolate :)

Similar Threads

  1. Sending array of data to client
    By k80sg in forum New To Java
    Replies: 0
    Last Post: 03-16-2010, 07:48 AM
  2. Replies: 1
    Last Post: 01-09-2010, 02:16 PM
  3. sending data to printer directly
    By Abhinav.k in forum Advanced Java
    Replies: 4
    Last Post: 12-09-2009, 07:26 AM
  4. Replies: 3
    Last Post: 12-05-2008, 08:34 PM
  5. Getting all the pages from a domain
    By eva in forum New To Java
    Replies: 0
    Last Post: 12-25-2007, 11: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
  •