Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Making Java Act Like A Form

Reply
Thread Tools

Making Java Act Like A Form

 
 
dougjrs@gmail.com
Guest
Posts: n/a
 
      02-06-2007
Good Evening!

I am trying to create a "wrapper" for a search page. The search page
that I have supports searching by zip codes, but not proximity. What
I would like to do is create a front end for the search and then pass
a list of zip codes to the search program.

The problem that I am having is moving the person doing the search to
the results that come back from the search. I just present the client
with a blank page not the results page. My "vision" is that my user
would provide me a zip code, I will create a list of zip codes withing
x mines of that zip code and then pass it to the search program.

When you have a form you go to the action="" page when you click on
submit. What happens to me is that when I send the POST to the server
I stay on the page. I need it to move to the page that I am doing the
post to.


I have created a very simple page to test what is going on. Here is
the code:
<%@ page language="java" import="org.apache.commons.httpclient.*,
org.apache.commons.httpclient.methods.*" %>


<%
String url = "http://localhost:8080/printer.jsp";
try {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod( url );

// Configure the form parameters
method.addParameter( "p", "Java" );

// Execute the POST method
int statusCode = client.executeMethod( method );
if( statusCode != -1 ) {
String contents = method.getResponseBodyAsString();
method.releaseConnection();
System.out.println( contents );
}
}

catch( Exception e ) {
e.printStackTrace();
out.println(e.toString());
}

%>

When I run this I get a 100% blank page. I want to go to the page
that the post is being done to.

Any help is appericated and thanks in advance for help!
Doug

 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      02-06-2007
On Feb 6, 3:03 pm, (E-Mail Removed) wrote:
> Good Evening!
>
> I am trying to create a "wrapper" for a search page. The search page
> that I have supports searching by zip codes, but not proximity. What
> I would like to do is create a front end for the search and then pass
> a list of zip codes to the search program.
>
> The problem that I am having is moving the person doing the search to
> the results that come back from the search. I just present the client
> with a blank page not the results page. My "vision" is that my user
> would provide me a zip code, I will create a list of zip codes withing
> x mines of that zip code and then pass it to the search program.
>
> When you have a form you go to the action="" page when you click on
> submit. What happens to me is that when I send the POST to the server
> I stay on the page. I need it to move to the page that I am doing the
> post to.
>
> I have created a very simple page to test what is going on. Here is
> the code:
> <%@ page language="java" import="org.apache.commons.httpclient.*,
> org.apache.commons.httpclient.methods.*" %>
>
> <%
> String url = "http://localhost:8080/printer.jsp";
> try {
> HttpClient client = new HttpClient();
> PostMethod method = new PostMethod( url );
>
> // Configure the form parameters
> method.addParameter( "p", "Java" );
>
> // Execute the POST method
> int statusCode = client.executeMethod( method );
> if( statusCode != -1 ) {
> String contents = method.getResponseBodyAsString();
> method.releaseConnection();
> System.out.println( contents );
> }
> }
>
> catch( Exception e ) {
> e.printStackTrace();
> out.println(e.toString());
> }
>
> %>
>
> When I run this I get a 100% blank page. I want to go to the page
> that the post is being done to.
>
> Any help is appericated and thanks in advance for help!
> Doug



System.out.println does NOT print to the jsp output., try
"out.println" instead of "System.out.println"


%@ page language="java" import="org.apache.commons.httpclient.*,
org.apache.commons.httpclient.methods.*" %>

<%
String url = "http://localhost:8080/printer.jsp";
try {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod( url );

// Configure the form parameters
method.addParameter( "p", "Java" );

// Execute the POST method
int statusCode = client.executeMethod( method );
if( statusCode != -1 ) {
String contents = method.getResponseBodyAsString();
method.releaseConnection();
out.println( contents );
}
}

catch( Exception e ) {
e.printStackTrace();
out.println(e.toString());
}

 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      02-07-2007
(E-Mail Removed) wrote:
>> <%@ page language="java" import="org.apache.commons.httpclient.*,
>> org.apache.commons.httpclient.methods.*" %>
>>
>> <%
>> String url = "http://localhost:8080/printer.jsp";
>> try {
>> HttpClient client = new HttpClient();
>> PostMethod method = new PostMethod( url );
>>
>> // Configure the form parameters
>> method.addParameter( "p", "Java" );
>>
>> // Execute the POST method
>> int statusCode = client.executeMethod( method );
>> if( statusCode != -1 ) {
>> String contents = method.getResponseBodyAsString();
>> method.releaseConnection();
>> System.out.println( contents );
>> }
>> }
>>
>> catch( Exception e ) {
>> e.printStackTrace();
>> out.println(e.toString());
>> }
>>
>> %>


Daniel Pitts wrote:
> System.out.println does NOT print to the jsp output., try
> "out.println" instead of "System.out.println"
>
>
> %@ page language="java" import="org.apache.commons.httpclient.*,
> org.apache.commons.httpclient.methods.*" %>
>
> <%
> String url = "http://localhost:8080/printer.jsp";
> try {
> HttpClient client = new HttpClient();
> PostMethod method = new PostMethod( url );
>
> // Configure the form parameters
> method.addParameter( "p", "Java" );
>
> // Execute the POST method
> int statusCode = client.executeMethod( method );
> if( statusCode != -1 ) {
> String contents = method.getResponseBodyAsString();
> method.releaseConnection();
> out.println( contents );
> }
> }
>
> catch( Exception e ) {
> e.printStackTrace();
> out.println(e.toString());
> }


Why write this as JSP at all? You use nothing but scriptlet. If you wrote this
as a standard servlet, you'd probably find that existing methods like doPost()
will obviate the need to handle certain things yourself.

Take a gander at the Model-View-Controller, or "Model 2" paradigm for web
apps, as supported by Struts or JSF.

<http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html>

The JSF section of <http://java.sun.com/javaee/5/docs/tutorial/doc/>:
<http://java.sun.com/javaee/5/docs/tutorial/doc/JSFIntro.html#wp114889>

<http://struts.apache.org/>

- Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making os.unlink() act like "rm -f" Roy Smith Python 2 12-11-2010 08:47 PM
Can I make this look like a button and act like an a href ? active ASP .Net Web Controls 4 04-03-2007 01:50 PM
java class to act like a browser Edward Java 3 08-04-2006 08:02 PM
C++ objects that act like Java/C# objects. Steven T. Hatton C++ 8 06-28-2005 05:26 PM
Re: Making a table cell act like a submit button? C.F. ASP .Net 0 04-13-2005 07:49 PM



Advertisments