Display a servlet form when no parameters are passed

W

Will

I have a notty problem trying to display
a form initially. The form works fine when
it submits to itself, but throws millons
of errors when it first displays, 'cos it
has no requested parameters yet until
someone hits the submit button. Here
it is:

class MyServlet extends BaseServlet
.....
if (request params == true){
hundreds of lines of code
that process the requested
parameters. } // end of very large if
.....
println("my form etc");
println("my form etc"); hundreds more lines.
end class

It seems ridiculous to put an 'if' {}
statement round hundreds of lines
of code. And I think variables go out
of scope too. But if I do nothing
it just hangs because my hundreds of
lines of code have no parameters.

There must be an easy answer, but
I am getting more and more bogged
down in this problem. Any one hit
this problem before? (JRun app server)
 
S

segex

I'm not shure I got everything right, but maybe (maybe you have and I
understood everything wrong) you have to initialize the vars with some
default value like "" or so?
 
R

Raymond DeCampo

Will said:
I have a notty problem trying to display
a form initially. The form works fine when
it submits to itself, but throws millons
of errors when it first displays, 'cos it
has no requested parameters yet until
someone hits the submit button. Here
it is:

class MyServlet extends BaseServlet
....
if (request params == true){
hundreds of lines of code
that process the requested
parameters. } // end of very large if
....
println("my form etc");
println("my form etc"); hundreds more lines.
end class

It seems ridiculous to put an 'if' {}
statement round hundreds of lines
of code. And I think variables go out
of scope too. But if I do nothing
it just hangs because my hundreds of
lines of code have no parameters.

There must be an easy answer, but
I am getting more and more bogged
down in this problem. Any one hit
this problem before? (JRun app server)

First, look into JSPs for generating HTML.
Second, use separate request handlers for different things. Creating
the HTML to display the form and responding to the user submitting the
form are two different things and you should not try to handle both of
them in the same method. Frameworks such as Struts and Spring can help
with this.

HTH,
Ray
 
W

Will

I cannot use JSP for technical
reasons, Struts? no time to
learn all about those. (Sep 15th deadline) I'll
have to use servlets, maybe
have an html form that calls the
servlet with the same html embedded
into the servlet as is in the html, But I can handle
displaying a blank form from a servlet
that submits to itself, I won't have to
double up on the embedding. But the
null parameter handling code etc is building
up into something like a haystack.
 
R

Raymond DeCampo

Will said:
I cannot use JSP for technical
reasons, Struts? no time to
learn all about those. (Sep 15th deadline) I'll
have to use servlets, maybe
have an html form that calls the
servlet with the same html embedded
into the servlet as is in the html, But I can handle
displaying a blank form from a servlet
that submits to itself, I won't have to
double up on the embedding. But the
null parameter handling code etc is building
up into something like a haystack.

Which is the problem that JSPs, Struts and the like were invented to
solve. If you can't use them, then oh well....

Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top