Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 31st, 2004, 05:52 PM
sachsav sachsav is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 sachsav User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
IllegalArgumentException Space in URL error J2ME

Could somebody please help. I have created a food menu in J2ME to be displayed on the phone. The user then selects the item they would like once selected the item is entered into an access database. A servlet has been used to do this however i get an error which says java.lang.IllegalArgumentException: Space character in URL I have looked at the URL and cannot see any spaces so what could possibly be wrong. The selection is retrieved by using the getSelectedFlags() method.
I include my code below. I will appreciate any help PLEASE

SERVLET
Code:
import java .io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
public class PizzaExpOrderServlet extends HttpServlet {
 
 private Statement stmt = null;
 private Connection conn = null;
 private String URL ="jdbc:odbc:PizzaExpOrder";
 
 public void init (ServletConfig config)
 
  throws ServletException {
   super.init(config);
   
   try {
	Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
	conn = DriverManager.getConnection(URL, "", "");
	
   }
   catch (Exception e) {
	e.printStackTrace () ;
	conn = null;
   }
   
  }
  
  
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   
   String pizzaexporder = request.getParameter("pizzaexporder");
   
   if ( pizzaexporder == null)
   {
	response.sendError(response.SC_BAD_REQUEST, "Unable to read parameters");
	return;
   }
   
   PrintWriter output = response.getWriter();
   response.setContentType ("text/html");
   
  
	
   
   boolean success = insertIntoDB("'"+"',' ','" + pizzaexporder + "'");
   
   if (success) 
	output.print ("<H2>Thank You For Ordering Your Customer Reference is:</H2>");
   
   else
	output.print ("<H2> An error ocurred</H2>");
	
   output.close();
   
   
  }
  
  
  
  
  private boolean insertIntoDB (String stringtoinsert){
   try{
	
	stmt = conn.createStatement ();
	stmt.execute("INSERT INTO PizzaExpOrder values (" + stringtoinsert + ");");
	stmt.close();
	
   }
   catch (Exception e) {
	System.err.println ("Error: Problems with adding new entry");
	e.printStackTrace();
	return false;
   }
   return true;
  }
  
  public void destry ()
  {
   try {
	conn.close();
   }
   catch (Exception e) {
	System.err.println ("Problem closing the database");
	
   }
  }
  
 }


MIDLET
Code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;

public class FormPizzaexp extends Form implements CommandListener, Runnable {
 
   private ChoiceGroup pizzaexpMenu;
   private MainScreen midlet;
   private Command cmdBack;
   private Command cmdSelect; 
  
  public FormPizzaexp (String title, MainScreen midlet ){
	 
	 super (title);
  this.midlet = midlet;
  cmdBack = new Command("Back", Command.BACK, 1);
	 cmdSelect = new Command("Select",Command.OK, 2);
	 pizzaexpMenu = new ChoiceGroup ("What would you like to Order?", Choice.EXCLUSIVE, 
	 new String [] {"ANTIPIZZE", "Garlic Bread £1.95", "Bruschetta £3.25", "Baked Dough Balls £1.95", "SALADS AND VARIATIONS", "Mozzarella and Tomato Salad £6.45", "Lasagne Pasticcate £7.10", "Tortellini £7.10", "PIZZE", "Margherita £4.95", "American Hot £7.70", "Soho Pizza £6.95", "Sloppy Giussepe £7.15", "WINE", "House White Bottle 75cl £10.95", "Half House White Bottle 37.5cl £5.95", "House Red Bottle 75cl £10.95", "Half House Red Bottle 37.5cl £5.95", "SOFT DRINKS", "Coke £1.65", "Sprite £1.65", "Mineral Water £1.00", "Apple Juice £1.65", "DESSERTS", "Choclate Fudge Cake £3.85", "Tiramisu £3.85", "Vanilla Ice Cream £2.10"}, null);
	 append(pizzaexpMenu);
	 addCommand(cmdBack);
	 addCommand(cmdSelect);
	 setCommandListener(this);
	
	}
 
 public void commandAction(Command c, Displayable s) {
	 if (c == cmdBack)
	   midlet.displayMainForm ();
	  else if (c == cmdSelect){
	   
		  Thread t = new Thread(this);
		  t.start();
		
	   
	  
  }
  
   }
   
   public void run(){
	submitOrder();
   }
  
	private void submitOrder () {
  
  HttpConnection http = null;
  InputStream iStrm = null;
  String pizza = null;
  
  boolean selected[] = new boolean [pizzaexpMenu.size()];
	 pizzaexpMenu.getSelectedFlags(selected);
	 
	 for (int i=0; i<pizzaexpMenu.size(); i++)
	  if (selected[i] == true)
	  pizza = pizzaexpMenu.getString(i);
		 System.out.println(pizza);
		 
	 
  
  String url ="<A href="http://localhost:8000/pizzaexporder/PizzaExpOrderServlet"+"pizzaexporder="+pizza">http://localhost:8000/pizzaexporder/PizzaExpOrderServlet"+"pizzaexporder="+pizza; 
	
	
   try { 
	http = (HttpConnection) Connector.open(url);
	http.setRequestMethod(HttpConnection.GET);
	 if (http.getResponseCode() == HttpConnection.HTTP_OK){
	 iStrm = http.openInputStream();
	 int length =(int) http.getLength();
	  if (length>0){
	  byte servletData[] = new byte [length];
	  iStrm.read(servletData);
	  append("You passed to the servlet" + new String(servletData));
	  
	 }
	 else
	 append("Unable to read the data");
	}
   
   }
   catch (Exception e){
	append("Network error");
	System.out.println(e.toString());
   
   }finally {
   try {
	if (iStrm!=null){
	 iStrm.close();
	}
	if (http != null){
	http.close();
	}
	}catch (IOException e){
	 e.printStackTrace();
	}
	
   } 
	
 } 
}   
	
	
	
   
  
  
  
  
  

Reply With Quote
  #2  
Old April 1st, 2004, 05:03 AM
sachsav sachsav is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 sachsav User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Can anyone please help

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > IllegalArgumentException Space in URL error J2ME


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT