hi!
this is what i m trying to do i m trying to display a form which has a drop down menu n a table displaying some basic data....now i want once user selects an item i want the form to submit to itself with the selected item as parameter..n refresh the table contents based on that...
now where i m stuck is that how do i check if the form has been submitted or it's the first time the form is displayed....
then how do i obtain the request parameter to display the contents based on selected item
Im using JSP's ...pls help

Recommended Answers

All 3 Replies

First of all you will need javascript: http://www.w3schools.com/default.asp

There is the onchange function. You can have the form submit there:

<form name="formName" action="">

<select name="param" onchange="document.formName.submit()">
...
</select>

</form>

Then at the beginning of your jsp:

<%

String param = request.getParameter("param");
if (param!=null) {
   // form was submitted
} // if param is null then you just browse to this page without submitting

%>

If you need to read data from database, I would suggest to submit to a Servlet, read the data and come back to the jsp page. There is a tutorial at the beginning of the jsp forum about MVC which you might want to read

thanks a million for responding just wanted to tell u that i was doing the same i was checking if the requested parameter is not null the i run my code and in the else part i wanted to display what should be visible on the page when you first view it....like

if( request.get Parameter("Distselect")!=null)
{
//my stuff
}
else
{
//my initial stuff
}

the problem is the else part doesn't get executed when the page is viewed first. I would like to tell u that i m just fetching some data from a text file and that's simple code which is working well so i m not sure if i really need a servlet to do that for me all i want is that my initial data gets displayed when the page is viewed for the first time....n i m also submitting the form on on click event in my select list called Distselect....so if we can figure out away to display the intial data that would be a gr8 help...thanks

What's inside the "else" should be displayed.
Have you tried to see the value of the request?

<%
String Distselect = request.getParameter("Distselect");
System.out.println("Distselect is: "+Distselect);

if (Distselect==null) {
  System.out.println("Inside If");
%>
   IFIFIFIFIFIFIFIF
<%
} else {
  System.out.println("Inside If");
%>
   ELSEELSEELSE
<%
}
%>

Just try only this and see what happens.
Also you could post some more code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.