search
HomeDatabaseMysql TutorialJSP入门教程(3)_MySQL

JSP入门教程(3)_MySQL

Jun 01, 2016 pm 02:08 PM
jspgetting StartedobjectengineTutorialdataform

第二课:用HTML表单

大多数情况下,商业的网站都要有一些表单,比如说输入一下消费者的姓名啦,地址啦,或者敲一个词来用搜索引擎来查一下啦,或者市场人员从来访者处收集一些数据供参考什么的。

那些表单传回的数据怎么处理的?

来访者通过表单向JSP引擎输入了数据,并保存在了request对象中,那么接下来怎么办?

图2-1向你展示了数据流是如何在服务器和客户之间传递的(至少在SUN的JSP reference implementation是这么做的,别的JSP引擎工作起来可能会有一点点的不同,其实大同小异,都差不多)



字儿太小了,可能看不大清吧?俺来解释一下了只好。

首先,JSP引擎把存放在request对象中的数据发到JSP页面指定的服务器端的组件(JavaBeans组件, servlet,或者enterprise bean),组件收到这些个数据以后,有可能再存这些数据到数据库或者其他的地方存放起来,同时,返回一个response对象给JSP引擎。JSP引擎再把response对象传给JSP页面,这时的页面包含了定义好的格式和从服务器端得到的数据。这时JSP引擎和Web服务器再发送一个整理好的完整的页面给客户,也就是这们在浏览器上看到的结果。客户和服务器间的通信协议可以用HTTP,当然也可以用其他的。


Request和Response对象在你制作的JSP原代码中起作用。到于request对象到底怎么用,我要在接下来详细的讲给你听。

如何创建表单

用HTML定义一些有代表性的表单做成一个JSP文件,然后用JSP标签在表单和服务器端对象(通常都用Bean)传递数据。一般情况下是这么干的:

1、 写JSP原文件,创建一些HTML的表单并命名。

2、 在Java文件里写Bean,定义属性,GET或者SET方法来配合已经被你指定好名字的表单。

3、 回到JSP原文件中,增加标签来创建一个或者调用一个现成的Bean。

4、 增加标签设置HTML表单中需要SET方法的Bean的属性。

5、 增加标签设置HTML表单中需要GET方法的Bean的属性。

6、 如果需要处理更多的用户数据,用request对象。

说了半天你可能看不懂,其实看一个例子你就懂了。

先看一个简单的hello的例子吧:

这段程序其实还是计算机程序里那个最经典的“hello,world”的程序,只不过呢,我使他挠了一点弯儿,使他看起来比较智能和复杂。首先你输入你的名字,然后Duke跟你说:“hello!”





看看代码吧:

dukebanner.html

















   
 
JSP入门教程(3)_MySQL



主JSP文件:hellouser.jsp



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

MySQL String Data Types: A Comprehensive GuideMySQL String Data Types: A Comprehensive GuideMay 08, 2025 am 12:14 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,idealforconsistentlengthdatalikecountrycodes;2)VARCHARforvariable-lengthstrings,suitableforfieldslikenames;3)TEXTtypesforlargertext,goodforblogpostsbutcanimpactperformance;4)BINARYandVARB

Mastering MySQL BLOBs: A Step-by-Step TutorialMastering MySQL BLOBs: A Step-by-Step TutorialMay 08, 2025 am 12:01 AM

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

BLOB Data Type in MySQL: A Detailed Overview for DevelopersBLOB Data Type in MySQL: A Detailed Overview for DevelopersMay 07, 2025 pm 05:41 PM

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

How to Add Users to MySQL from the Command LineHow to Add Users to MySQL from the Command LineMay 07, 2025 pm 05:01 PM

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

What Are the Different String Data Types in MySQL? A Detailed OverviewWhat Are the Different String Data Types in MySQL? A Detailed OverviewMay 07, 2025 pm 03:33 PM

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.