JSP
Hi, I have a basic question.
I'm using HTML JSP page to build an web base application. I have one form in the JSP page and I I use that form to send the page to a servlet to validate the record when I added a record. Now I want a second button name "search" which will be use to search a record and display it in another JSP page. In order to do so I must have another form that I will use send my submission to another servlet. How do I nested two or more form in a HTML page. I know it sound confusing but please understand. Thanks
[547 byte] By [
Hailuaa] at [2007-10-2 0:29:31]

You don't nest forms. Maybe it's possible according to the HTML specification, but I've never seen it in practice. What's preventing you from having 2 buttons on the same form? It's done all the time.
Hie,I guess this url can u help you out.Try reading the tutorials.Click the Chapter 4 above the book image. http://java.sun.com/developer/Books/javaserverpages/Murach/
Sorry to confuse you. I have no problem having two buttons on one form. But the two buttons each have it own servlet to validate. I can only have one "Method" and Action" on a form and I can only send the submission to one servlet in one form. The two buttons Add and Search all have it own servlet to go to validate the data. How can I send each button submit to a different servlet. Below is an exampe of my program.
<form name = "add" method = "post" action = "xxxx.xxxx.Servlet"
Button Add Go Here
></form>
NOTE: the add button once pressed will first take the data to the xxx.xxx.Servlet, servlet to validate the data. How do I send the Search button to a second servlet let called it servlet xxx.xxx.Servlet2. This really confuse me.
Thanks for your help.
<input type="submit" name="button1" value="Press this button to invoke servlet1">
<input type="submit" name="button2" value="Press this button to invoke servlet2">
Then in your controller servlet:
if(request.getParameter("button1") != null){
//button1 is pressed.
//forward to servlet1.
}
else if(request.getParameter("button2") != null){
//button2 is pressed.
//forward to servlet2.
}
Hope this helps.
You can put multiple forms a single HTML page, they are independent, and each will have its own action. I don't use JSP much, but here's a Velocity example where cells in a table are actually forms:
<table>
<tr>
<th>
<form>
$state.member.name
</form>
</th>
<td>
<form method=GET action="Logoff.do">
<button type="submit" onclick="return(confirm('Do you really want to log off?'))">
Log Off
</button>
</form>
</td>
<td>
<form method=GET action="Main.do">
<button type="submit">Main Page</button>
</form>
</td>
#if ($navTopics)
<td>
<form method=GET action="Topics.do">
<button type="submit">Topics Page</button>
</form>
</td>
#end
#if ($navSystem)
<td>
<form method=GET action="System.do">
<select name="system" size=1 onchange="submit()">
#foreach ($s in $state.systems)
<option value="$s"
#if ($state.system == $s)
selected
#end
>System=$s</option>
#end>
</select>
</form>
</td>
#end
#if(!$adminactive)
#if ($state.member.hasRole("admin"))
<td>
<form method=GET action="ToAdmin.do">
<button type="submit">Administration</button>
</form>
</td>
#else
<td>
<form method=GET action="ToProfile.do">
<button type="submit">Update Your Profile</button>
</form>
</td>
#end
#end
</tr>
</table>
<hr>
Can I clear it up. Do I have to create another servlet file to have the the button validate first or can I put it within the JSP page. Thanks
I usually use javascript to set the action of the form when I have more than one button.
<html>
<script>
function goToFirstPage(){
document.myForm.action="FirstPage.jsp";
document.myForm.submit();
}
function goToSecondPage(){
document.myForm.action="SecondPage.jsp";
document.myForm.submit();
}
</script>
<form name=myForm method=POST >
<input type=button name=pageOne value="Go To First Page" onclick=goToFirstPage()>
<input type=button name=pageTwo value="Go To Second Page" onclick=goToSecondPage()>
</form>
</html>