The difficulties encountered when using Web project development Myeclipse

1. when connecting to the database: Unsupported major.minor Version 51.0

The reason: For example: the use of an external jar package jdk1.7 compiler, use jdk version of this jar engineering package for jdk1.6, so version does not support. That low version of jdk version of the compiler to perform high-jar package will throw an error.
Knowledge Expansion: major.minor version, which is equivalent to a major and minor version number of the software, but here is the identification of a Java Class major version number and minor version number.

:( If this solution using an external jar package jdk1.7 compiler, for example)

(1) platform jdk compiled version of myeclipse (or project changes only need to change): Right-click the project name -> preferences-> the Java Compiler
(2) jdk version: preferences-> java-> installed JREs selected jdk1.7 (. If you do not add this version of jre)
(3) will run tomcat jdk version is also changed to 1.7: preferences-> myeclipse-> server-> tomcat-> choose their own use (tap tomcat, to see which is enable the ) tomcat-> jdk-> change

The following is a correspondence relationship jdk version number, appearing above 51.0, refers to the major version number is 51, the minor version number is 0

Step 2. Import sql driver package to the jsp:

 . a drive package into WebRoot- items> WEB-INF-> lib inside
 b create a path: Right-click the driver package in the lib, select Build Path option appears, then select Add to Build Path

After 3.jsp connection database, the database data read distortion occurs. (Ie the data in the database for the Chinese, jsp used in select statement to query garbled after reading)

jsp database connection encoding specified in the statement is incorrect.
Solution: useUnicode written in the code connecting to the database = true & characterEncoding = UTF-8 & autoReconnect = true

4.get and post request by:

get submission: method = "get" request and the address bar the way, the hyperlink (<a href="">) request mode, the default belong to get submission.
the difference between get and post request methods:
. A get displayed in the address bar request information (address bar but the information that can be accommodated is limited, 4-5KB, Ruoguo request the presence of large data files, pictures, etc., will not accommodate all the address bar the data error); POST is not displayed.
b. file upload, post must be

5. post and distortion occurs when the get request:

garbled request a. post.
Solution: In the beginning jsp page plus <% request.setCharacterEncoding ( "UTF-8 ");%>

                Or java code segments jsp page <% ...%> at the beginning of write request.setCharacterEncoding ( "UTF-8"); statement.

Garbled b. Get request.

Principle: We used as running Tomcat Servlet and JSP container, while the inner code is Tomcat default ISO 8859-1, so to get request mode, the data (URI) will be appended to the transmitted resource access, which is encoded Tomcat By default, if you modify the coding Tomcat, it will not get garbled for all requests, including redirection and hyperlinks. Recommendation: When using tomcat, first in server.xml, get Unicode mode (tomcat7 and earlier default encoding is iso-8859.1, after tomcat8 default is utf-8)
specific measures:

. i: a uniform coding of each variable (not recommended)
    new new String (the old code, the new code)
 EG: name = getParameter ( "name");

        name = new String(name.getBytes("iso-8859-1"),"utf-8");

ii: modify the port found in the server.xml Tomcat Tomcat regional profile was added URIEncoding = "utf-8" in the interior thereof. In the login screen, I used this method to solve.

6. / meanings:

  in a web.xml /: item representative of the root directory (i.e., / <url-pattern> in)
corresponds to: http: // localhost: 8080 / project name /
  B / JSP in: Representative root server ( i.e. a form or a hyperlink request servlet class)
is equivalent to: http: // localhost: 8080 /

7.myeclipse items in the root directory:

There are two root directory, a is the WebRoot, another is to construct a path (e.g., the src), are the same level. Also you can right-click in the project, create a Source Folder, the folder belong to the build path, and src same level, also called the root directory.

8. If jsp error occurs: at The Import Xxx (class name) can not be resolved
to try solutions:
. A (possibly jdk, tomcat version issue) right project - after> build path, to which the error of the libary or lib delete, re importing
b empty various caching: click clean under the Project, or enter tomcat directory, delete subdirectories inside work
c restart the computer.
d If you import the class in jsp page, if the direct write <% page import = "category. name "%> necessary to add the package name <% page import = the class name" package name. class name "%>

9.jsp page connect to the database, execute a stored procedure (with parameters), error: Para (first parameter name) is not acquired.

Reason: the parameters are obtained from the label input in the jsp pages, may be provided within the input tag name attribute value, is acquired by getParameter (). But also you can set the id attribute value when the value of the id attribute and name attribute values ​​are the same, get less than the value of this parameter error occurs.

Solution: just set the name attribute value in the input tag, or the same input tag, id attribute value and the name attribute value to be different

10. In the Windows command prompt, enter: the Java -version , you can view the machine jdk version

11. In general, modify web.xml, configuration files, java code, you need to restart the tomcat service
   but if you modify the jsp \ html \ css \ js, do not need to reboot, refresh the page on the line.

12. jsp pages <%> out.print and out.println not write the transport, to transport, need to add "<br/>", i.e. out.print (), <% =%> directly parse html code.

13. css percentage height provided but has no effect.
 The reason: the percentage of the size of the parent element is a relatively high degree of size. It is the width: the width of the parent element can be determined without setting percentage. But for different heights: If the parent element of an element does not determine the height, it can not effectively use the height = XX% of style.
eg: attempts to add body {height: 100%}, but did not use. Since the height of the parent element of the body can not be fixed. Html therefore need to set the height of the element; percentage * or the height is provided in {}.


14. set the background image to the div, div tag should be written on the back. If the individual to write css set div, is not displayed.
eg: <div class = "deng_lu2 " style = "background-image: url ( 'image / background 1.jpg');">

15. The pitch of the table.
  border-collapse, the property setting the distance between adjacent cell borders. There are two values, if it is Collapse, refers to the adjacent sides are combined, if it is separate, independently represents a border.
 Only border-collapse: the separate (i.e. separate frame) are satisfied, then set border-spacing attribute, and is equivalent to tag attributes cellspacing (cell margins), i.e. border-spacing: 0 is equivalent to cellspacing = "0" . Usually used as such border-spacing: 10px 10px; refers to the spacing of the ranks.

16. Question: Chinese js file in the message sent to the garbled jsp page.
 The reason: .js file created by default gbk encoding, and the jsp page is utf-8 encoded pages.
Solution: Modify coding js file, right-click the js file -> properties to set the character encoding.


17. Using the session in the servlet.
a. seesion first import servlet interface package. EG: Import the javax.servlet.http.HttpSession;
B session object created in doGet () or doPost () method. EG: Request.getSession the HttpSession session = ();
C may be used in the session code.


18. servlet objects acquired out. (A problem similar to above)
. A package is first introduced: Import java.io.PrintWriter;
B created out object: PrintWriter out = response.getWriter (); .

19. Since the name attribute value to the input tag in the form, not with the same name sql keywords, or use request.getParameter when the servlet interface () Gets, parameter error will be reported.

20. When you insert a picture into jsp, the picture extension .jpg and .JPG differentiated, case-sensitive.

21. calls Servlet, jsp page blank, with only This is class mvc.servlet.Query_car, using the POST method the information.
Solution: Shut down the Tomcat server, reopen.

22. In the sql server, manually modify the data in a table, the error message: " has been updated, or deleted row value either can not make the line a single row or multiple rows to change the "
Cause: The memo is deleted the row line is not unique, since no primary key table, duplicate values.
Solution:
  Method One: Use the sql statement, add a primary key to the table in
  two: the table delete and re-create, set up primary key of this creation, then qualified data into a table
  Method three: Use the sql statement, delete duplicate The data

23. After jsp page and database connections, pay attention to the implementation of sql statement: execute update, insert, delete statement does not return a result set (when a query returns a result set select). ResultSet object may be used, but not rs.next () method, because they do not return a result set.
Recommendation: When data operations (e.g., update, insert, delete) statement, can be defined PreparedStatement object PS, using ps = con.prepareStatement (sel); sql statement SEL execute the statement, using ps.executeUpdate (); Statement update, the statement must have.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Published 20 original articles · won praise 2 · Views 1607

Guess you like

Origin blog.csdn.net/weixin_42132733/article/details/103649293