• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

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
0
Flash5
Asked:
Flash5
  • 4
  • 3
  • 2
  • +1
2 Solutions
 
vikraman_bCommented:
>>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
0
 
petmagdyCommented:
Is the another page a Web component (Servlet or JSP) in the same Web application?
0
 
Flash5Author Commented:
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
vikraman_bCommented:
or use
jsp:forward
0
 
vikraman_bCommented:
JSP Syntax
<jsp:forward page={"relativeURL" | "<%= expression %>"} />
or
<jsp:forward page={"relativeURL" | "<%= expression %>"} > 
<jsp:param name="parameterName"
          value="{parameterValue | <%= expression %>}" />+
</jsp:forward>
Examples
<jsp:forward page="/servlet/login" />
<jsp:forward page="/servlet/login">
<jsp:param name="username" value="jsmith" />
</jsp:forward>
0
 
Flash5Author Commented:
>> Is the another page a Web component (Servlet or JSP) in the same Web application?

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

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

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

then

<%
        someMethod(with those parameters);
%>

0
 
Flash5Author Commented:
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
}
0
 
petmagdyCommented:
then on our source JSP u can do:

request.setAttribute("param", "value");
 getServletConfig().getServletContext().getRequestDispatcher("TargetJsp.jsp").forward(request, response);

on the target jsp:
value = request.getAttribute("param")
0
 
KartikShahCommented:
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now