DoPost correctly activated but request = null !??! help!
Hi there,
I'm coding a client in j2me, learning from books like Core J2ME. Its been going fine but i've hit a snag, i can select the method to doPost fine servlet side - my problem is the request seems to be null when this is done. The client also calls the doGet method which functions perfectly.
The whole point of the doPost method is for me to send a message -with a few characters that wouldnt be appropriate for a URL request style (i.e. full stops -basically im sending messages).
i've beeen Reading the examples and trying to get the code working but still no joy... the code i have is below for each method:
first method from the client:
// send a POST request to Web server
public void sendMessage() throws IOException
HttpConnection hc = null;
DataInputStream dis = null;
DataOutputStream dos = null;
String message = "";
// the request body
String requeststring = "u="+userDetails+"&m="+compose.getString()+"&t="+recipient.getString()+"&a=st";
try
// an HttpConnection with both read and write access
hc = (HttpConnection)
Connector.open(URLIP, Connector.READ_WRITE);
// set the request method to POST
hc.setRequestMethod(HttpConnection.POST);
// obtain DataOutputStream for sending the request string
dos = hc.openDataOutputStream();
byte[] request_body = requeststring.getBytes();
// send request string to Web server
for (int i = 0; i < request_body.length; i++) {
dos.writeByte(request_body);
// flush it out
dos.flush();
// obtain DataInputStream for receiving server responses
dis = new DataInputStream(hc.openInputStream());
// retrieve the responses from Web server
int ch;
while ((ch = dis.read()) != -1) {
message = message + (char) ch;
} finally {
// free up i/o streams and http connection
if (hc != null) hc.close();
if (dis != null) dis.close();
if (dos != null) dos.close();
System.out.println(message);
the servlet doPost Code
public void doPost (HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
String name = "";
String value = "";
// parse out the value pair from the POST body
// the expected string is "request=gettimestamp"
try {
BufferedReader br = request.getReader();
String line;
String requeststring = "";
System.out.println(request.getQueryString());
while (( line = br.readLine()) != null)
requeststring = requeststring + line;
StringTokenizer sTokenizer =
new StringTokenizer(requeststring, "=");
if (sTokenizer.hasMoreTokens())
name = (String) sTokenizer.nextToken();
if (sTokenizer.hasMoreTokens())
value = (String) sTokenizer.nextToken();
} catch (Exception e) {
System.err.println(e);
// turn auto flush on
PrintWriter out =
new PrintWriter(response.getOutputStream(), true);
response.setContentType("text/html");
String message = "ok";
response.setContentLength(message.length());
out.println(message);
Here's a method that I've used to successfully POST to a servlet:
* Sends a POST request to the servlet, putting the given String into the contents.
* @param String containing the request contents.
* @return InputStream to receive messages from the servlet.
* @exception IOException if anything goes wrong with the communication.
public InputStream sendPostMessage(String contents) throws IOException
URLConnection connection = this.servletURL.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// Write the contents as POST data
DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
String encodedContents = URLEncoder.encode(contents, DEFAULT_ENCODING);
dos.writeBytes("message=" + encodedContents);
dos.flush();
dos.close();
return connection.getInputStream();
} I'd also recommend that you write an echo servlet or JSP that you can send a GET or POST request to and have the echo just send the result back. It'll help you make sure that what you send is arriving and all the connections are okay.
See if this helps you.
%
Similar Messages
-
Import is not available all other actions are active but not import help?
Import is not available all other actions are active but not import help? I wish to import bookmarks from internet explorer, I am using windows 7
Make sure that you do not run Firefox in permanent Private Browsing mode.
*https://support.mozilla.com/kb/Private+Browsing
*You enter Private Browsing mode if you select: Tools > Options > Privacy > History: Firefox will: "Never Remember History"
*To see all History and Cookie settings, choose: Tools > Options > Privacy, choose the setting <b>Firefox will: Use custom settings for history</b>
* Deselect: [ ] "Permanent Private Browsing mode" -
Safari crashes on launch -- but Request for Help fails to post...
For a week, I've tried to post a message,to the "Safari for Mac" forum. But it fails to post.
Instead, I get a message, advising "We'll be right back".
Other people have been posting messages during this week -- so what's wrong with mine?
My message is a request for a solution to my problem of Safari crashing immediately on launch.
The message includes a Safari Crash Report, which is quite detailed (as a textEdit file, compressed Archive, it runs to 29KB).
Hoping that this brief plea gets through. TIA.The problems are caused by third party input managers/enhancers that have not yet been updated by their developers to comply with the standards used by Safari 4.1.and/or Safari 5.
In your case these are:
007af000 /Library/InputManagers/SIMBL/SIMBL.bundle/Contents/MacOS/SIMBL 007f4000 /Library/InputManagers/Ecamm/Ecamm Plugin Loader.bundle/Contents/MacOS/Ecamm Plugin Loader
00e0a000 /Library/InputManagers/Ecamm/Plugins/iGlasses.plugin/Contents/MacOS/iGlasses 00e45000 /Users/john/Library/Application Support/SIMBL/Plugins/VideoboxSafariPlugin.bundle/Contents/MacOS/VideoboxSafari Plugin
02cd6000 /Users/john/Library/Internet Plug-Ins/iGetterBundle.plugin/Contents/MacOS/iGetterBundle 02e02000 /Users/john/Library/Internet Plug-Ins/iGetterBundle.plugin/Contents/Resources/iGetterSafariBundle.bundle/Con tents/MacOS/iGetterSafariBundle
You fill find them in one or either of these folders:
Home/Library/Input Managers
Hard Disk/library/Input Managers
Hard Disk/Library/Application Support
although the exact location is indicated in your crash report as quoted above - look under 'Binary Images'.
Close Safari and delete them, then restart Safari and it should be working normally. Alternatively drag them to the desktop and restart Safari. then add them back one at a time, restarting Safari every time, until you find the one (or more) causing the crash.
Check with the developers of the plug-in/s in question for updates that are Safari 5 compliant. -
i have iphone 5 with icloud accont but isn't for me need to remove oredy erase my iphone but while activated it request enter your i cloud account plz help me
Contact whoever you purchased the phone from. That's called activation lock. There is no way to bypass it without the credentials for the account that was used to lock it.
-
I have incorrectly entered an email address that is not valid. I have requested the change to the correct email but if cannot verify it as the verification email is being sent to the email address that I entered incorrectly and is invalid. Help!
Hey Givemepaperandapen,
Thanks for using Apple Support Communities.
For more information, take a look at:
Apple ID: Associating and verifying email addresses with your Apple ID
http://support.apple.com/kb/he68
How to edit or change your Apple ID and primary email address
Have a nice day,
Mario -
I've tried downloading iOS5 several times and after an hour each time I get a message that says my network connection has timed out. But I can't find any information about "timing out" or how to correct the situation. Any help?
Disable your antivirus and firewall, and try again.
-
I have a problem with my iphone 4. My 3G always stays activated but I lose my network signal. The bars all get lost and I'm not able to receive / send sms, mms or phone calls. Could you guys please help me fix this problem? Ios 5.1.1
I haven't gotten a new sim card because the problem has been presenting itself in various cards not only mine. So far, all I've done is reset my network settings.
Last night, I turned off the 3G tab and it had all the signal bars. Today, I did the network reset and it's working apparently. But like I said before, previously the bars just disappear and the iphone only has the 3G activated. -
i buy new iphone but i have problem in my mobile. it's need activation and i dont no how to active its need sim activation but i take it from UK and my brother send me this phone in saudi arabia i am old coustomer of apple so please help me i am suck
If the phone is locked to a carrier then you will need the carrier to unlock it And only the carrier can do that.
-
So I went ot update my ipod on itunes....and a box appeared saying to make sure the internet setting are correct and active, but my internet is working fine. What do I do?
Sounds like this:
Update Server
Try:
- Powering off and then back on your router.
- iTunes for Windows: iTunes cannot contact the iPhone, iPad, or iPod software update server
- Change the DNS to either Google's or Open DNS servers
Public DNS — Google Developers
OpenDNS IP Addresses
- Try on another computer/network
- Wait if it is an Apple problem -
Help, just had my iphone 3 but can't connect to wifi, i get as far as the password put in the correct password but it won't accept it, any ideas?? Thanks
What type of encryption are you using with your wireless network -WEP or WPA?
If your wireless router supports both which it should unless it is quite old and you are using WEP, try switching to WPA which is much more secure than WEP which is important if you have a Windows PC or any Windows based device connected to your network.
In addition, when was the last time you checked Netgear's website to see if there is a firmware update available for your wireless router model that you haven't installed? -
My iphone 4 has been stolen at Nagpur /Maharashtra /India . icloud is activated but internet is off . but still ringing pls help me to track it
Log on to your computer, and go to www.findmyiphone.com and login to your apple ID and it will give you the location of your iphone. If you need extra help, i strongly suggest you contact apple via phone call.
I wish you the best of luck! -
I bought an Adobe photoshop elements 12 and successfully installed. I failed to activate as it said I am offline whereas I am online. I tried offline activation but failed. Could someome help me? Thanks
Hi Agathe,
Please refer to the below link and follow the steps.
http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html
Thank you for posting on Adobe Forums. -
I bought my phone from apple store they said its sim free but now i insert the sim signal is coming but its showing on screen activation required can anyone help plz
If your iPhone is new and you purchased from an Apple (Corporate ) Retail Store then you have to activate after inserting a new carrier sim for first time
See here
http://www.apple.com/support/iphone/essentials/ -
Trying to start my IMac click on my admin icon and enter the correct password but then flashes to white screen and back to sign in, my desktop wont come on ... help!!!!
Boot to the Recovery HD:
Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
When the menubar appears select Terminal from the Utilities menu. Enter resetpassword at the prompt and press RETURN. Follow instructions in the dialog window that will appear.
Or see Reset a Mac OS X 10.7 Lion Password and OS X Lion- Apple ID can be used to reset your user account password. -
I purchased an album a while ago and just got a new ipod so i downloaded all my purchases, and it all downloaded, but it downloaded the wrong songs. It says on the title that it is the correct song, but the audio is a completely different album. any help?
If you have been using the mac.com Apple ID to make iTunes purchases recently, then there should be no issues continuing to use it with the new iPhone. I would abandon the new ID as you will never get Apple to merge the two IDs. I have had a mac.com ID for years and continue to use it with my iPhone 4S.
Tell us the issues that you encounter trying to set up the iPhone with the mac.com account.
Maybe you are looking for
-
I would like to know how to add images and create a slide show
The image I try to add to my web page show up as grayed out boxes and never show up. I would also love to learn how to make a slide show to enhance my home page. Thank you!
-
Export PDF in Captivate 5 and Publishing CP4 project in CP5
When I publish flash (swf) videos in CP4, I always tick the "Export PDF" option to also get the PDF version - and then offer the PDFs for download as an alternative to watching online (or send them via e-mail). I have learned to live with the fact th
-
JClient Component Demo - not compatible with 9.0.3 (?)
I try to load the JClient Component Demo from OTN using th README supplied, and I have several problems: 1. The README says to unzip the JClientBindingDemo directly into mywork, AND indicates that a DIRECTORY with the same name will be created. This
-
Creating LOV in Table Action.
Hi, Can we create a LOV in table action ,if yes then is LOV Action button is the only way of achieving that.As lot of issue are there if i use LOV action instead of LOV as no criteria item is present in LOV action button. Thanks
-
Extract Data from Essbase to Oracle
We have a requirement of extracting data from Essbase and loading the same into Oracle Need to know what are the possible ways of doing it and which is the best one. Are there any ODBC drivers, api's that come with Hyperion Essbase server installatio