2014-09-02 127 views
0

大家好我正在使用JavaScript來填充值。我使用這個腳本JavaScript從另一個變量填充值

String Vegs[]= request.getParameterValues("Vegs"); 
String qty_carrot=request.getParameter("quantity_carrot"); 
String qty_tomato=request.getParameter("quantity_tomato"); 
String qty_cabbage=request.getParameter("quantity_cabbage"); 
String qty[]; 
qty[0]=qty_carrot; 
qty[1]=qty_tomato; 
qty[2]=qty_cabbage; 

,但它說,錯誤的局部變量數量是尚未初始化..

還當我的代碼更改爲這個

String qty[]=new array(3); 
qty[0]=qty_carrot; 
qty[1]=qty_tomato; 
qty[2]=qty_cabbage; 

它說陣列不能爲分辨率爲

堆棧軌跡:@aravind

堆棧軌跡:

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) 
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:199) 
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:446) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:361) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:336) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:323) 
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88) 

回答

0

你必須這樣創建數組:

String qty[] = new String[3];//<-- 3 is the size of array, you may change it 
+0

@ user1799574,你的職位是在JSP中,而不是JavaScript數組scriplet!試一試我發佈的答案。 – Arvind 2014-09-02 05:25:32

+0

是的,我曾嘗試說,類型不匹配不能從字符串轉換爲字符串[] – 2014-09-02 05:28:05

+0

@ user1799574,你可以發佈堆棧跟蹤,這將是有益的 – Arvind 2014-09-02 05:29:29