Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Run a Servlet Without a Submit Button

Thread view: 
dmckeon@ameritas.com - 14 Jun 2006 15:18 GMT
I am new to Java and am trying to figure out how to run a servlet
without the need for a user to click a submit button.  I have a web
service that converts a file to PDF and then a servlet that displays
the PDF file in the browser.  Here is the code I have in the JSP:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<META http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<META name="GENERATOR" content="IBM Software Development Platform">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet"
    type="text/css">
<TITLE>IgRetConvTest.jsp</TITLE>
</HEAD>
<BODY>
<H1>Retrieve and Convert</H1>
<jsp:useBean id="proxy"
class="getconvert.IgRetConvProxy"></jsp:useBean>
<%
    session.setAttribute("filename",
String.valueOf(proxy.retrieveConvert("<?xml version='1.0'
encoding='UTF-8'
?><IMG-PATH>C:\\\\TEST\\</IMG-PATH><IMG-NAM>TEST.IMG</IMG-NAM>")));

%>
<FORM action="/IgRetConvClient/PDFDisplay" method="post">
<INPUT type="submit" name="Submit" value="Display Image">
</FORM>
</BODY>
</HTML>

How can I run "/IgRetConvClient/PDFDisplay" without using "submit"?
Oliver Wong - 14 Jun 2006 15:25 GMT
>I am new to Java and am trying to figure out how to run a servlet
> without the need for a user to click a submit button.  I have a web
> service that converts a file to PDF and then a servlet that displays
> the PDF file in the browser.  Here is the code I have in the JSP:

[most of the code snipped]
> <FORM action="/IgRetConvClient/PDFDisplay" method="post">
> <INPUT type="submit" name="Submit" value="Display Image">
> </FORM>
[...]

> How can I run "/IgRetConvClient/PDFDisplay" without using "submit"?

   The user has to somehow navigate to that URL. There are many ways to
this that don't involve clicking on a button labelled "Submit". One of them
is to type in the URL directly into the browser's address bar, for example.

   - Oliver
dmckeon@ameritas.com - 14 Jun 2006 15:34 GMT
> >I am new to Java and am trying to figure out how to run a servlet
> > without the need for a user to click a submit button.  I have a web
[quoted text clipped - 14 lines]
>
>     - Oliver

All of the code I supplied is in a JSP.  If the user navigates to the
JSP I need a way to run the servlet without them clicking "submit".
Can you give me some specific examples of how to do that?
Oliver Wong - 14 Jun 2006 15:58 GMT
>> >I am new to Java and am trying to figure out how to run a servlet
>> > without the need for a user to click a submit button.  I have a web
[quoted text clipped - 18 lines]
> JSP I need a way to run the servlet without them clicking "submit".
> Can you give me some specific examples of how to do that?

   Doesn't the user navigating directly to
http://[yourserver]/IgRetConvClient/PDFDisplay cause the servlet to run?

   - Oliver
dmckeon@ameritas.com - 14 Jun 2006 16:02 GMT
> >> >I am new to Java and am trying to figure out how to run a servlet
> >> > without the need for a user to click a submit button.  I have a web
[quoted text clipped - 23 lines]
>
>     - Oliver

That's not the way it's structured or the way we need it to work.
dmckeon@ameritas.com - 14 Jun 2006 16:06 GMT
> >> >I am new to Java and am trying to figure out how to run a servlet
> >> > without the need for a user to click a submit button.  I have a web
[quoted text clipped - 23 lines]
>
>     - Oliver

I'm sorry -- I think I know what you mean.  Are you suggesting I use a
redirect???
Oliver Wong - 14 Jun 2006 16:54 GMT
>> >> >I am new to Java and am trying to figure out how to run a servlet
>> >> > without the need for a user to click a submit button.  I have a web
[quoted text clipped - 27 lines]
> I'm sorry -- I think I know what you mean.  Are you suggesting I use a
> redirect???

   Well, I wanted to get a yes-or-no answer to my question to check if my
assumptions were correct. Assuming they ARE correct, what I'm basically
saying is that there is virtually an infinite number of ways to get the
servelet to run, depending on what you want. All that needs to be done is to
ensure that the client eventually navigates to that link.

   So you could use a form, or an <a href="/path/to/your/servlet"> link, or
a redirect, or javascript, or an applet, or a ShockWave flash animation, or
a Windows .url shortcut, etc.

   - Oliver
christopher@dailycrossword.com - 15 Jun 2006 01:01 GMT
Google sometimes does it by having an <img> tag href to a servlet that
returns something unimportant to the browser.  the <img> tag can have a
size 0 so it does not interrupt the page.
steen - 15 Jun 2006 10:28 GMT
> > >I am new to Java and am trying to figure out how to run a servlet
> > > without the need for a user to click a submit button.  I have a web
[quoted text clipped - 18 lines]
> JSP I need a way to run the servlet without them clicking "submit".
> Can you give me some specific examples of how to do that?

Well if I understand you correctly, just make the following change to
your jsp :
<BODY onLoad="document.forms[0].submit();">

that will cause the form to auto-submit when your jsp is called. No
need for the user to hit a submit button.

(btw. this is more a javascript question)

/Steen
dmckeon@ameritas.com - 15 Jun 2006 15:23 GMT
> > > >I am new to Java and am trying to figure out how to run a servlet
> > > > without the need for a user to click a submit button.  I have a web
[quoted text clipped - 29 lines]
>
> /Steen

<BODY onLoad="document.forms[0].submit();"> works like a charm!!!
Thanks so much (and sorry for posting in the wrong group)!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.