JSP + MySQL + MyEclipse + JavaScript Project Development

Source: Internet
Author: User
1. We know that there is a created jsp project. How can I import it to MyEclipse? Right-click PackageExplorer -- import -- General -- existingprojectsworkflow workspace. In this project, MySQL port: 3306 password: wjdTomcat: 8080 2. Why use Dreamweaver and MyEclipse at the same time? Use D at the same time

1. We know that there is a created jsp project. How can I import it to MyEclipse? Right-click PackageExplorer -- import -- General -- existingprojectsworkflow workspace. In this project, MySQL port: 3306 password: wjdTomcat: 8080 2. Why use Dreamweaver and MyEclipse at the same time? Use D at the same time

1. We know that there is a created jsp project. How can I import it to MyEclipse?

Right-click Package Explorer --> import --> General --> Existing Projects into Workspace.

MySQL port: 3306 password: wjd Tomcat: 8080 in this project

2. Why use Dreamweaver and MyEclipse at the same time?

At the same time, Dreamweaver and MyEclipse are used to facilitate website construction. Dreamweaver is used to layout pages, while MyEclipse is mainly responsible for the coding of jsp in the background and in the background. Create a site in Dreamweaver and set the site address to the project directory of MyEclipse.

After modifying the page content in Dreamweaver, refresh the entire project in MyEclipse. After modifying the page content in MyEclipse, "Whether to load external modifications" appears in Dreamweaver ", if "yes" is selected, the editing and synchronization are ensured.

3. How do I import an SQL file into MySQL?

Use Navicat software to implement the interface of MySQL. Open Navicat to create a connection, create a database, and then click tools> console> copy the content in the SQL file to the console editing column. Click Press enter. The SQL import is successful.

4. Chinese garbled characters

1. Follow these steps to set JSP page encoding in MyEclipse:

Choose windows> Preferences> MyEclipse> Files & Editors> JSP> encoding: Set to iso000046/Unicode (UTF-8 ).

2. On the JSP page:

<% @ Page contentType = "text/html; charset = character encoding" pageEncoding = "character encoding" %>

The encoding option for saving the JSP file must be consistent with the encoding configured in the pageEncoding attribute on the jsp page (or the encoding configured in the contentType attribute when the pageEncoding attribute is not available, the priority of the two is: pageEncoding> contentType.

3. You also need to set the encoding to UTF-8 in MySQL.

4. When submitting a form, add the request. setCharacterParameter ("UTF-8"); Statement to the doPost function.

5. Compare alert ("msg"), confirm ("msg"), prompt ("msg ")

Warning box: window. alert (str) or alert (str)

Confirmation box: answer = window. confirm (str) or answer = confirm (str)

Prompt box: returnStr = window. prompt (targetQuestion, defaultString)

Or prompt (targetQuestion, defaultString)

The biggest difference between alert () and confirm () Is that alert () does not return values. There are two types of return values for confirm (): return false and return true. When the confirm () dialog box jumps out, click OK. the return value is true. Click Cancel to return false.

6. Create a JSP page

When you create a JSP page, select JSP (Basic templates ).

Static parts of jsp pages, such as HTML and CSS tags, are used to complete page layout and display styles. dynamic parts of jsp pages, such as script programs and jsp

JSP declaration example:

<%! Int number = 0;

Synchronized void count () {number ++ ;}

%> // This code segment declares a variable number and a method count, which can be used anywhere on the jsp page.

<% Count (); %>

You are the number of <% = number %> customers visiting this site

JSP built-in objects include:

1. out: transfer information to the client browser

Eg1: out. println ("Hello, JSP ");

Eg2: out. println (I) <=> <% = I %>

2. request: encapsulate client request information;

3. response: responds to client requests;

4. session: A session requested by the client. Sessions can access the properties and methods of session objects from the client to the server until they are disconnected from the server.

VII. request object and response object

Request object: the client's request information is encapsulated in the request object, through which you can understand the customer's requirements and then respond. It is an instance of the HttpServletRequest class.

Response object: The response object contains information about the response to the customer request, but it is rarely used directly in JSP. It is an instance of the HttpServletResponse class.

8. Compare the usage scope of page, request, session, and application

Within a page range: page

Within the range of one server request: request

Within the range of one session: session

Within the scope of an application server: application

Document is js ( ...), Not java (<%>) object;

The value obtained by $ {...} is the value in the request range, which has the same effect as request. getAttribute.

<% =... %> The reason why the value can be obtained is because the above javascript definition actually exists within the page range.

9. Configure and use FCKeditor In the JSP Environment

The following statements are required to use the online editor:

<% @ Page language = "java" import = "com. fredck. FCKeditor. *">

....

<%

FCKeditor oFCKeditor;

OFCKeditor = new FCKeditor (request, "EditorDefault ");

OFCKeditor. setBasePath (request, getContextPath () + "/fckeditor /");

OFCKeditor. setVaule ("");

Out. println (oFCKeditor. create ());

%>

10. MVC Mode

After the servlet is introduced, the servlet completes the control function and the jsp simply displays the page. This is the MVC mode (Model-View-Controller: Model-View-Controller ).

Jsp + javaBean + servlet mode design:

1. An index. jsp page. For example, a form is used to display the content of a message book. It is used to submit the content of the message book;

2. A servlet File Operate. java. This file receives the data submitted by the form, which is generally processed in three ways: return all the message information of index. jsp; Delete the message information; insert the message information.

3. A Class DBOperate. java that encapsulates database operations. The design of this class adopts the singleton design mode.

11. Servlet Configuration

Servlet/jsp Mapping URL:/servlet/add_servlet

File Path of web. xml:/project name/WebRoot/WEB-INF

12. upload images

To upload an image, upload the image to the server and save it to a folder. Put the image name in the database. Generally, the image name is renamed based on the current time. For more information, see ***.

13. JSP connection to MySQL

DriverManager is an interface for managing JDBC drivers. It obtains the reference of the Connection object through the getConnection method. Connection con = DriverManager. getConnection ();

Statement is a tool that submits SQL statements to the database and returns corresponding results.

ResultSet executeQuery (String SQL) throws SQLException

Int executeUpdate (String SQL) returns the number of records that have changed

Boolean execute (String SQL) determines whether execution is successful

The PreparedStatement interface inherits the Statement interface. When an SQL Statement needs to be modified and executed repeatedly, PreparedStatement is usually used.

14. Page flip Function

 

15. error: integer and int Conversion

The final problem encountered in the project is the conversion of Interger and int. The solution is to use forced conversion.

Int count = Interger. valueof (). intValue ();

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.