permaculture playing cards*
The moose likes Servlets and the fly likes Databases and jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Databases and jsp" Watch "Databases and jsp" New topic
Author

Databases and jsp

babi bartolome
Greenhorn

Joined: May 10, 2001
Posts: 6
HELP! i don't know what to do?
In my jsp file, i use a onClick event to call a function which look like this:
<input type="button" value="ok" onClick=<% inform(); %>>
</body>
</html>
<%! public void inform()
{
DataUtility datautility = new DataUtility();
Query query = new Query();
datautility.setTableName("Company");
datautility.setFieldName("CompanyName");
datautility.setFieldData("KKK",DataUtility.STRING_DATA);
datautility.setFieldName("CompanyCode");
datautility.setFieldData("DJ",DataUtility.STRING_DATA);
query.add(datautility.getTableName(), datautility.getFieldName(), datautility.getFieldData());
}
%>
So whenever i would click the ok button, it must go to the
inform() function which i write after the </html> tag. The problem is whenever i upload this jsp file in the server the inform() function would be automatically used... why? how can i use the onClick function before it will work? HELP ME PLS.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Please carefully distinguish between Java code and JavaScript code.
Java code executes in the server, as the HTML page is being generated. At this stage, the page has not even arrived at the browser yet. Your JavaScript is nothing but passive text in a buffer.
JavaScript code executes in the browser, as the HTML page is being displayed. The Java servlet which generated the page has stopped executing and is completely inaccessible.
What you are trying to do is call a Java function (inform()) from a JavaScript hook (onClick). This cannot work at all.
- Peter
babi bartolome
Greenhorn

Joined: May 10, 2001
Posts: 6
hey Peter ! thanks a lot, so you mean the onClick cannot call the inform () because onClick is a javascript while the inform() is a java ...
um, my question now is what will i do to call the inform() function whenever i click the "ok" button as i have typed earlier. (pls refer above). pls help me...
kamlesh jainani
Greenhorn

Joined: May 09, 2001
Posts: 5
i have the same problem too but somewhat different. my event is onChange on the select tag... how could i call my class whenever a user changes his selection on the box?? can javascript function call a class function or a java code??
try using this approach, but i'm not sure about it...
Florence Cheung
Greenhorn

Joined: Mar 18, 2001
Posts: 24
Hi,
I think you can write java code in a servlet or a jsp, for example generate a servlet called "InformServlet.java", deploy it.Let's say the url of it is /informServlet. Then in your html file or jsp file you can write:
<form action=/informServlet method=post>
<input type=submit value="ok">
</form>
When you click "ok" button, the InformServlet.java will be executed.
Hope this helps.
Florence
babi bartolome
Greenhorn

Joined: May 10, 2001
Posts: 6
Pls... help me
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

It might help if you told us what you were trying to achieve.
For example, if it's a change to data on the page then the button can submit a form that passes some data to a servlet and returns the required page...
Dave.
babi bartolome
Greenhorn

Joined: May 10, 2001
Posts: 6
hey thanks for the help to all of you guys...
um, but the problem is whenever i execute my jsp file as florence has said:
<form method=post action=/myurl>
<input type="submit" value="ok">
</form>
when ever i clicked the "ok" button this is what the browser will say to me...
"Method Not Allowed
The requested method POST is not allowed for the URL /myurl"
i just wanted to ask what will be the solution for this question?
thanks for your help, i hope you may have patience with me, i am stuck with this problem for a long time.
babi bartolome
Greenhorn

Joined: May 10, 2001
Posts: 6
To Dave,
i'm sori dave i didn't put my goal in what i am trying to do.
well, honestly Dave, what i am trying to achieve is that in my jsp file, there will be some combo box and text boxes that the user will have to input, after that the "ok" button will suppose to add this data in the server of what the user has input in the first combo box and text box.
hope you understand what i am trying to say.
thanks a lot Dave for your concern...
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Ah ha.
Basically you have to get used to requests and responses.
The client requests a page, you respond by generating the page and sending it.
The client requests another page sending some data (ie fills in a form) you use the data to create the new page and respond with that page.
If we turn this into code,
The user requests a page (Page1.jsp)
This might be the code that gets executed to return the first page... (note that we specify that the details will be sent to Page2.jsp)

When they fill in the details and hit the 'submit' button, it results in the request data being sent to Page2.jsp
The page we return can be generated based on the data sent back...

We gathered the data sent to us and used it to generate a new page on the server side. Would could just as easily have parsed the data, saved it to a database or used it to validate the user.
I hope this helps. It's a bit of an intuitive leap trying to separate the code on the client and server, but it isn't rocket science
Dave.
babi bartolome
Greenhorn

Joined: May 10, 2001
Posts: 6
To all people who helped me in my project,

Dave, Florence, Peter thanks a lot for the help!!! it is working now...
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

No charge
Dave.
Let life be a lesson to you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Databases and jsp
 
Similar Threads
Can parameters be scriptlet in onclick? If not, alternate?
XSL and Javascript
Reset Button
servlet exception error in my code(urgent)
onClick button and JSP