简体   繁体   中英

How can I send html/javascript values to sql and return it back to the same page in jsp?

I started out with an html page. Then, I renamed the file with a .jsp extension, as I will be using jsp to accomplish this particular task.

Which is: I wish to take a value from the page on a form, send it to sql to be used in a where clause, then send the data set back to the same page. Now, I could likely employ AJAX, instead of submitting a form. I would appreciate some advice, like a step-by-step procedure, for I'm bewildered about at least a couple of items. 1) Can I write the JSP code in the same page? 2) Can or should I write SQL inside the JSP code? 3) Should I Have another page set up just for JSP?

I suppose I'm looking for a "Hello World" explanation, as I've primarily worked with non-java based languages in the past.

Thank you.

1) You can write JSP (Java) code in the same file, but it is not recommended. 2) Same as 1. you can write SQL code in JSP, but you shouldnt. 3) HTMLs renamed to JSPs are perfectly valid jsp files.

I suggest that you use a MVC framework like Spring MVC to do your task. Here's a tutorial .

UPDATE: Standard JSP & servlet tutorials

  1. http://archive.coreservlets.com/Chapter3.html

  2. http://archive.coreservlets.com/Chapter16.html

  3. http://archive.coreservlets.com/Chapter15.html

  4. http://archive.coreservlets.com/Chapter3.html

For quick and dirty, you should look at using the JSTL SQL tags. They're pretty easy to use, actually, and eliminate much of the JDBC cruft if you simply embedded Java.

This page is a decent little example that covers most of the fundamentals, for SQL with JSTL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM