Hi,
I've been trying to get two parameters passed from a html to a jsp
page. I can read the correct values of the passed parameters but
I am having difficulties distinquishing between those values in an
if-else statement.
The idea is, I need my jsp page to know how the call to it was made. It
can be an INPUT or a VIEW mode.
I've got an entries.html which is:
<html>
<body>
<form action="DocView.jsp" method="POST" accept-charset="UTF-8">
Enter a document of type:
<SELECT NAME="doctype" SIZE=1>
<OPTION VALUE="article">article
<OPTION VALUE="book">book
<OPTION VALUE="manual">manual
</SELECT>
<INPUT TYPE="submit" VALUE="Go">
</FORM>
<BR>
<form action="DocView.jsp" method="POST" accept-charset="UTF-8">
Or view an existing document with id
<SELECT NAME="docid" SIZE=1>
<OPTION VALUE="1">1
<OPTION VALUE="2">2
<OPTION VALUE="3">3
</SELECT>
<INPUT TYPE="submit" VALUE="Go">
</FORM>
</body>
</html>
and a DocView.jsp one:
<%
String doctype = request.getParameter("doctype");
String docid = request.getParameter("docid");
String mode = "";
if(docid != "") {
mode = "VIEW";
}
else if( doctype != ""){
mode = "INPUT";
out.println("doctype = " + doctype + ", mode = " + mode +"<BR>");
out.println("docid = " + docid + ", mode = " + mode);
%>
The if-else statement should identify the type of call was made to
DocView, based on that, actions will be taken.
The code is just to demonstrate the idea of what I am doing. The
actuall code reads data from a MySQL database.
As a result of Docview.jsp I get the correct value of docid if I chose
an id value or a null if not. The same with doctype,
either the choosen doctype is displayed or a null. But the variable
mode does not change.
It is alway VIEW. Or actually it always gets the value that assigned
first to it. If I change else-if with the if statement, then the mode
will always be INPUT.
Now that leads to the conclusion that mode has to be reinitialized! but
How?
I can do the same thing with PHP, but there I can use $_GET['param']
and $_POST['param'] and different if-else statement, and it works
perfectly. Here is just a snip if the statements in PHP (sorry for
having to post a php code, but this might clearify my problem more).
$mode="";
$docid=$_GET['docid'];
$doctype=$_POST['doctype'];
if($docid!="") {
$mode="VIEW";
} else {
$docid=$_POST['docid'];
if ($doctype!="") {
$mode="INPUT";
} elseif ($docid!="") {
$mode="EDIT";
}
}
(the EDIT mode will be added to the jsp later), but this code does
exactly what I want. how can realize the same in my jsp code?
I appreciate any help on that.
Thankfully,
Michael
jessu - 28 Sep 2005 05:02 GMT
if( docid != null ) {
//parameter docid wont be null if it is view mode
mode = "VIEW";
}
else {
//parameter docid will always be nulll in this case, because there
is no input names docid in this corresponding form
mode = "INPUT";
}
------
FeedFeeds : A new way to read news and blogs!
http://www.feedfeeds.com
heinzmic@gmail.com - 28 Sep 2005 18:06 GMT
> if( docid != null ) {
> //parameter docid wont be null if it is view mode
[quoted text clipped - 11 lines]
> FeedFeeds : A new way to read news and blogs!
> http://www.feedfeeds.com
Thanks Jessu,
I should not think PHP wenn writing JSP. I kept trying it with "" and
thinking this means null in JSP as well!
What about the statements
$docid=$_GET['docid'];
and
$docid=$_POST['docid'];
(in php) in the targeted "jsp" page? is there something similar to this
in JSP, or the method getParameter("param") does all that?
Thanks again.
Ulrich Hobelmann - 29 Sep 2005 00:45 GMT
> Thanks Jessu,
> I should not think PHP wenn writing JSP. I kept trying it with "" and
> thinking this means null in JSP as well!
I recently took a look at PHP and couldn't believe how crappy its design
was. Even "0" means null, not just 0 and ""!

Signature
Do or do not. There is no try.
Yoda