aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes submit button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "submit button" Watch "submit button" New topic
Author

submit button

Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Ok, I'll try this forum again, because this time it really is javascript.
I've got a "select" tag in my jsp that has 3 options in it. Then I have a submit button.
In the "form" tag, I put:
<form method=GET action="http://"URL"/servlet/DBInventory4">
(where URL is the correct url to my server).
If I press the submit button, should the value that the "select" tag contains get sent to the doGet method in my servlet (DBInventory4)?
(Did I make any sense?)
Annette
ali farid
Ranch Hand

Joined: Aug 26, 2000
Posts: 60
yes i should easily go. Have you tried it ?
Please tell me where javascript is involved here ?
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
You're right...all that form stuff is straight html.
Sorry.
Anyway, it's still not working, so I'm going to check my servlet one more time and make sure it's set up to receive the value properly.
I'll let you know what happens if it doesn't work again...
Annette
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
I know I transfered your question last time, but again, but I don't know Servlets, so I really can't answer it. I'll leave it here just in case someone else knows, but I would suggest putting it in the Servlet forum again. Basically I don't know what the doGet method does because I have never worked with servlets.
Sorry,
Bill
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Sorry Bill,
I'm having a hard time because no one in the other forum seems to know anything about the html side of things. I guess what I'm looking for is the correct code that goes in the jsp that will contain the value that the user types in so that from the servlet I can call that variable.
My assumption right now is that by creating the text field or the drop-down list box, whichever, that automatically creates the variable (ie, I can reference it from the servlet by simply calling the text box name). But then again, you probably won't know what I'm talking about if you've never worked with servlets.
I'll try again in the servlet forum, just in case no one here can help me!
Annette
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
I have worked with select lists in both javascript and ASP. With ASP you just call Request.QueryString("name_of_select_list")
With javascript, you have a two step function, first you get the selected index, and then you get the value of that index. I don't have the exact syntax in front of me, but if that will help I can get it for you.
I would have thought Servlets do it like ASP where you can get the value from the querystring or from the server variable of you submit via post method, by just calling for the name of the field.
I plan on starting to study for Servlets soon, so maybe I can do some research and find the answer for you.
Why don't you try posting your file so we can look at it. Will probably be long, but you can try.
Bill
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
It's not really all that long, I'm trying to get the functionality to work before I start making it all "pretty" and stuff. All it has is that one text field and a submit button:
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>First JSP test</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<h1><center>This is a test page</center></h1>
</head>
<form method=GET action="http://"url"/servlet/DBInventory4">
<br>
Table: <input type=text name="table">
<br>
<input type=submit>

</form>
</body>
</html>
Do you want to see the servlet code? Although you might not know what you're looking for.. Too bad you can't read a book like superman and just instantly know the subject matter
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Hey, post it anyways. I would always like to learn. And you are right. How I wish I could read a book in a day and just go. But I am still studying for the SCJP so I am waiting on servlets for right now. But it will be soon as my primary job is web developer.
Bill
ali farid
Ranch Hand

Joined: Aug 26, 2000
Posts: 60
Hi,
this is no problem. i've worked alot in servlets.
The HTML file:
===================================================
<HTML>
<HEAD>
<TITLE>
GetForm
</TITLE>
</HEAD>
<BODY>
<FORM action=http://localhost/servlet/GetForm method="GET">
<select name=hSelect>
<option value=1 selected>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
<BR><input type=text name=hText value=test>
<BR><input type=submit value="Submit">

</form>
</BODY>
</HTML>
======================================================
The Servlet:
=======================================================
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class GetForm extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = new PrintWriter (response.getOutputStream());
String jSelect = request.getParameter("hSelect");
String jText = request.getParameter("hText");

out.println("<html>");
out.println("<head><title>GetForm</title></head>");
out.println("<body>");
out.println("<br>The value of Select is: "+jSelect);
out.println("<br>The value of Text is: "+jText);
out.println("</body></html>");
out.close();
}
}
=========================================================
regds
ali
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
That's great Ali! Thanks! I'm going to compare it to my code and see if I can find the problem. I'm actually incouraged by the fact that I understand all your code!!
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
Annette,
I think I see one problem straight away. Your FORM's METHOD param should be a POST not a GET.

<FROM METHOD=POST ACTION="http://"url"/servlet/DBInventory4">
because you are POSTing (i.e sending) data. Give that a try.
Sean
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Oh!
I'll try it. Give me 10 minutes and I'll be back...
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
IT WORKS! IT WORKS! IT WORKS!!!
I can't believe it! That's great! Thank you sooooo much!
ali farid
Ranch Hand

Joined: Aug 26, 2000
Posts: 60
Actually the METHOD parameter in he FORM tag depends on the method you r using in the servlet. If you are using doGet() then either you specify the GET in the form or not(because default is GET) and if you r using doPost() then you should specify METHOD=POST in the FORM tag, and if you want to use any of these then u should use service() method in the servlet.
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
That's very true - the service method will handle either of these types of requests. However, if you want to send data along with the request (from the browser) you have to use a FORM tag with POST specified or dynamically re-write the url of the submit (or HREF) to include query string parameters (and this will work with a GET). This illustrates the main probem here, which was that the user data from the browser was never being passed along with the http request. I'm just happy Annette got things up and running
Sean
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: submit button