How I started building a JSP project from scratch

Source: Internet
Author: User
Tags apache tomcat

Recently, because the school has a curriculum design needs to be completed, there is no time to update the blog. It is the hardest thing to insist on.

Well, gossip doesn't say, come look at the point.

My topic is to design and implement an online forum, the specific needs to realize the functions of user registration, user login, post replies and other functions.

  1. I choose to use JSP to develop, so you have to install the Java operating environment, I use the eclipse for EE version, as for the configuration of the operating environment here do not say, casually Baidu, GG can be done.
  2. Then my JSP to run on Tomcat, so you have to install Tomcat, or to Baidu or GG, can also be done.
  3. The preparation of a database is also of course, I use SQL Server 2012, you can choose to use Oralce, MySQL, etc., for small projects is no different.
  4. Then create a new database, the data name I take the BBS, and then create a new user table, the table named Bbs_user. The table has a name, password, (just get a simple two columns, know the principle of the line).
  5. Open Eclipse, create a new Dynamic Web project (if your eclipse is Web-version, you will have this option, if you are not looking for one or other way to solve it).
  6. The new project name is called BBS, expand can see a lot of folders, it is recommended to put the JSP file under Web-content, (directly Click this folder right button to create a new JSP file line. ) Web-content, as the name implies. is to store the content of the Web page.
  7. Then there is a src folder, which is stored in Java files, your servlet files Ah, class method Ah and so on (what is the servlet will say what to do with, because I also do not understand, just say a method of operation, the principle of what must be self-reading)
  8. When you create a new JSP file, the inside of the form, the form of the submission method is set, usually post or get, and then the form of action, this should be filled, is a servlet, such as write action= "Bbsservlet". Of course, this will be an error, because there is no such bbsservlet ah, do not worry, the form must be set up, give each input a Name property, after the data acquisition is based on this identity to obtain. And then you have to have a submit button. <input type= "Submit" value= "commit" >,type value must be submitted, that is, the meaning of submitting this form, the logic here is when you fill out the contents of the form, click Submit, This form will be submitted to bbsservlet for processing.
  9. Well, here should be to create Bbsservlet, right-click the src folder, you can first create a package (package concept and function familiar with Java should know, do not say), and then in this package to create a servlet, named Bbsservlet, After creating the servlet, look at the code, you will find that eclipse has automatically written the default method for you, there is a doget, there is a dopost, see here everyone should understand, if your form when the Get method commits, in the doget inside write processing logic, If it is dopost, of course, is to deal with the data sent by the Post method.
  10. In the servlet, you can get the data submitted to the form, and then to process the data, it is generally stored in the database Ah, or modify the database corresponding data ah, the last point, it can be processed after the data to redirect to another page, such as I do login, If the user name password passed in the database is confirmed that there is no error, I can jump to the login successful page. So here, you probably understand that this servlet here is a data processing station, which receives the data of the form and then jumps to the page when it is processed.
  11. After all of the above steps, you can try to run your JSP page, select the page you want to run, right-run as and then choose running on the server, the first time you choose the server, you select Apache Tomcat, then select the Tomcat version, My is 7.0, just choose Tomcat 7.0, if you do not remember, you can access Tomcat in the native (how to access you should have seen in the above installation of Tomcat, is to confirm that your Tomcat installed the successful that), and then wait for it to run, if there is no error, What you see should be a page page, the content is the form you design, then you fill out your form, click Submit, the server gets your form data, and then processing, the processing will jump to the page you need (if you have to let it jump), and then you can determine the outcome of your process is wrong.
  12. Speaking of this, basically a simple registration process is complete, as for the core code, the Internet is some, when you understand the process, copy the code, you can handle it, you will understand.
  13. To mention the coding process may have some inexplicable errors, encountered this do not worry, calm down to think carefully about the logic process.
  14. I could say I was doing it because there is no jar to import the database to the database methods can not be used, (the embarrassment of capital, has been learning the front-end aspects, just touch the background of the writing is a bit miserable AH)

Well, I wish you beginners do not know how to build the whole service of learning smoothly, if there is a discussion about the length of the problem can be exchanged oh (outside the principle of what, the framework, what what what is not to hit my face, beg to let go)

How I started building a JSP project from scratch

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.