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
http://archive.coreservlets.com/Chapter3.html
http://archive.coreservlets.com/Chapter16.html
http://archive.coreservlets.com/Chapter15.html
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.
精彩评论