Link to home
Start Free TrialLog in
Avatar of Flash5
Flash5

asked on

Http post without using form method.

I want to write a jsp page that will posting data to another page but i don't want to use <FORM METHOD="POST">

anyone have an idea on doing this?

thanks
Avatar of vikraman_b
vikraman_b

>>I want to write a jsp page that will posting data to another page but i don't want to use <FORM METHOD="POST">

Hi just use
<form method =""> or <form method ="GET">
default get will fire if u put empty
Is the another page a Web component (Servlet or JSP) in the same Web application?
Avatar of Flash5

ASKER

Sorry, i think i didn't clearly explain on my question.
Actually what i want is write my own post method in jsp without using <FORM METHOD="POST">

thanks
or use
jsp:forward
SOLUTION
Avatar of vikraman_b
vikraman_b

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Flash5

ASKER

>> Is the another page a Web component (Servlet or JSP) in the same Web application?

Yes, it's Jsp too.
oic then u write

<%!
// this defines the method at instance scope

void someMethod(someParams
{
        // method goes here
}
>

then

<%
        someMethod(with those parameters);
%>

Avatar of Flash5

ASKER

what i want to do is something like the below midlet:

HttpConnection conn = null;
String url = "http://www.mysite.com/login.jsp";
String agent = "Mozilla/4.0";
String rawData = "userid=joe&password=guessme";
String type = "application/x-www-form-urlencoded";

String encodedData = encode( rawData ); // user-supplied

try {
      conn = (HttpConnection) Connector.open( url );
      conn.setRequestMethod( HttpConnection.POST );
      conn.setRequestProperty( "User-Agent", agent );
      conn.setRequestProperty( "Content-Type", type );
      conn.setRequestProperty( "Content-Length",
                              encodedData.length() );

      OutputStream os = conn.openOutputStream();
      os.write( encodedData.getBytes() );

      int rc = conn.getResponseCode();
      ... // process it
}
catch( IOException e ){
      // handle the error here
}
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

I am not very clear with your requirement, but what I understand from your question is that while submitting data from the browser, you do not want to use the html tab

<FORM METHOD="POST">

If my understanding is correct, then the this issue can be solved using JavaScript. What you can do is:

Put all the variables between the <FORM> </FORM> tag, and then write a javascript function like

    function submitForm()
      {
            document.forms[0].action="http://somedomain/submit.jsp";
            document.forms[0].method="post"; //document.forms[0].method="get";
            document.forms[0].submit();
      }

Regards

Kartik