App tips Format

Source: Internet
Author: User

  1. Do the app to build a JSP Web file.
  2. The menu bar picture uses the background picture each column to import two, one is M1, one is does not choose after the display M1s.
  3. When you truncate the picture of the menu bar, take the largest picture and intercept it as a square. It is generally 60*60 pixels.
  4. First of all, the framework HTML is not used in the page to delete, the use of comments to first write each page.
  5. The content of the Guide page is written at the end of the UL left an LI tag to display the homepage.
  6. After the HTML and CSS, write the background database, pure data with the servlet to deal with.
  7. database tables, each library creates a temporary user to manage, and the temporary user name is the name of the table, where% is allowed to log on offsite. When you set permissions, you can use the right button to select all.
  8. Under the source package, build a Java package, under which a servlet file is built, where the servlet file is named that part of the data, for example, this is the news page data to name newslist, to prevent conflicts; The URL pattern is set to/news/list.

    Servlets are available in two ways, one in the configuration file and one in the annotations of the document. When we choose the second one, we don't have to tick "add information to deployment."

  9. The data is stored in the form of a JSON of key-name key values. In the servlet file, define String json= "{\" key\ ": \" Value\ "}"; Out.print (JSON); Check for output. Writing methods such as:

    Try (PrintWriter out = Response.getwriter ()) {

    String json = "{\" key\ ": \" Value\ "}";

    try {

    Class.forName ("Com.mysql.jdbc.Driver");

    Connection conn = drivermanager.getconnection ("Jdbc:mysql://localhost:3306/apihost", "Apihost", "apihost");

    String sql = "SELECT * from Article_list";

    Preventing SQL injection, threading

    StringBuilder sb = new StringBuilder ();

    PreparedStatement stmt = conn.preparestatement (sql);

    ResultSet rs = Stmt.executequery ();

    while (Rs.next ()) {

    Sb.append ("{");

    Sb.append ("\" id\ ":");

    Sb.append (rs.getstring ("id"));

    Sb.append (", \" title\ ": \" ");

    Sb.append (rs.getstring ("title"));

    Sb.append ("\", \ "shijian\": ");

    Sb.append (rs.getstring ("Shijian"));

    Sb.append ("},");

    }

    Out.print ("[" + sb.substring (0, Sb.length ()-1) + "]");

    } catch (Exception e) {

    Out.print (E.getmessage ());

    }

    }

    }

  10. In the servlet package to write a database connection operation can, run without problems can write JS.
  11. In the form of closures, closures are designed to prevent name collisions, independent sections, and easy maintenance. The syntax is $ (function () {}), and the following table is specified:

$ (function ()

{

$ ("#homepage"). Load (function ()

{

Rssmasklayer.show ();//Loading

Rssloadbox.show ();//Load Box

$.getjson ("http://localhost:8084/api/article/list", function (JSON)

{

Rssmasklayer.close ();//self-encapsulated load icon

Rssloadbox.close ();//self-encapsulated load box

$ ("#homepage ul"). Mapitem (JSON);

$ ("#homepage ul"). Find ("Li"). Click (Function ()

{

$.getjson ("http://localhost:8084/api/article/view?id=" +$ (This). attr ("Dataid"), function (JSON)

{

$ ("#articleviewpage"). Mapjson (JSON);

});

});

});

}). Load ();

});

  1. To solve the cross-domain problem, add a line Response.setheader the header in the Java servlet ("Access-control-allow-origin","*");

    If only allow Baidu link to put Baidu's domain name in the back Response.setheader ("access-control-allow-origin", "www.baidu.com ");

    protected void ProcessRequest (HttpServletRequest request, httpservletresponse response)

    Throws Servletexception, IOException {

    Response.setheader ("Access-control-allow-origin", "*");

    Response.setcontenttype ("Text/html;charset=utf-8");//json,{"id", 1, "title": "Title 1", "matter": "Content 1", "Shijian" : 2431231},[{"id", 1, "title": "Title 1", "matter": "Content 1", "Shijian": 2431231}]

App tips Format

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.