JSP: Tag file operation database (User Registration Program)

Source: Internet
Author: User

ProgramDescription:

Programming to Implement the user registration function of a website, requires that you write a JSP page for users to enter registration information, get user input data on the receiving page, and output data on the browser at the same time, store information in the database.

Code:

Register the HTML page:

<% @ Page contenttype = "text/html; charset = UTF-8 "%> <% @ taglib tagdir ="/WEB-INF/tags "prefix =" inquire "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML> 

Register JSP page

<% @ Page contenttype = "text/html; charset = UTF-8 "%> <% @ taglib tagdir ="/WEB-INF/tags "prefix =" inquire "%> <HTML> <body bgcolor = cyan> <% request. setcharacterencoding ("UTF-8"); string NA = request. getparameter ("username"); string Pa = request. getparameter ("password"); string PAQ = request. getparameter ("passwordq"); string Ts = request. getparameter ("parameter X"); string TL = request. getparameter ("plever"); string TT = request. Getparameter ("ptime"); %> <% IF (! Pa. equals (PAQ) {out. print ("Your password is inconsistent, please enter \ n again") ;}%><%%> <br> your information is: <br/> Last Name: <% = Na %> <br/> password: <% = PA %> <br/> sex: <% = TS %> <br/> calendar: <% = TL %> <br/> Registration Time: <% = TT %> <br/> <inquire: addrecord export x = "<% = TS %>" Password = "<% = PA %>" plever = "<% = TL %>" ptime = "<% = TT %> "username =" <% = Na %> "> </inquire: addrecord> <br> </body> 

Tag file:

 <% @ tag pageencoding = "UTF-8" %> <% @ tag import = "Java. SQL. * "%> <% @ attribute name =" username "required =" true "%> <% @ attribute name =" password "required =" true "%> <% @ attribute name = "required X" required = "true" %> <% @ attribute name = "plever" required = "true" %> <% @ attribute name = "ptime" required =" true "%> <% string condition =" insert into product values "+" ("+" '"+ username + "', '"+ password +"', '"+ hour x +"', '"+ plever +"', '"+ ptime +"' "+ ")"; try {class. forname ("com. microsoft. sqlserver. JDBC. sqlserverdriver ");} catch (exception e) {} connection con; statement SQL; resultset RS; try {string uri =" JDBC: sqlserver: // 127.0.0.1: 1433; databasename = mystar "; con = drivermanager. getconnection (Uri, "sa", "sa"); SQL = con. createstatement (); SQL .exe cuteupdate (condition); con. close ();} catch (exception e) {out. print ("" + E) ;}%> 

Note:

[Question 1] garbled Chinese Characters

Add request. setcharacterencoding ("UTF-8") to each JSP page ");

[Question 2] Tag connection to the database failed

First, check whether the database to be connected is consistent. (If I mess up the database, I can suffer a big loss ~~ Time spent on white flowers)

[Question 3] When Using Attribute in a tag to pass a parameter, some of them can be passed, but some cannot be passed.

I searched for answers from the Internet for several days.

When something goes wrong, we should always go. Don't forget to restart tomcat.

Second, pay attention to the name in the attribute. The first letter is lowercase, and the second is uppercase.

I haven't slept well for several days.

To commemorate the elapsed time

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.