search
HomeDatabaseMysql TutorialJSP+MySQL+MyEclipse+JavaScript项目开发

一、已知有一个建好的jsp 项目,我如何导入到 MyEclipse 中? 右击 PackageExplorer--import--General--ExistingProjectsintoWorkspace 。 该项目中 MySQL 端口: 3306 密码: wjdTomcat : 8080 二、为何要同时使用 Dreamweaver 与 MyEclipse ? 同时使用 D

一、已知有一个建好的jsp项目,我如何导入到MyEclipse中?

右击Package Explorer-->import-->General--> Existing Projects into Workspace

该项目中MySQL端口:3306  密码:wjd  Tomcat8080

二、为何要同时使用DreamweaverMyEclipse

同时使用DreamweaverMyEclipse是为了方便网站建设,Dreamweaver用来布局页面,而MyEclipse主要负责后台与前台中jsp的编码。在Dreamweaver中建立站点,把站点地址设置成MyEclipse的工程目录。

当在Dreamweaver中修改页面内容后,在MyEclipse中刷新整个项目;当在MyEclipse中修改页面内容后,在Dreamweaver中会出现“是否加载外部修改”,选择“是”,则保证了两边编辑同步。

三、已知一个sql文件,如何导入MySQL中?

    利用Navicat软件实现MySQL的界面化。打开Navicat新建连接,然后新建一个数据库,然后点击工具-->console-->sql类型文件中的内容复制到console编辑栏目中,点击回车,sql导入成功。

四、中文乱码问题

    1、在MyEclipse中设置JSP页面编码步骤如下:

依次点击windows-> Preferences-> MyEclipse-> Files&Editors-> JSP-> encoding:设置为ISO10646/Unicode(UTF-8)

2在JSP页面中:

 字符编码" pageEncoding="字符编码"%>   

字符编码"

保存JSP文件时的编码选项必须与jsp页面中的pageEncoding属性中配置的编码一致(或者在没有pageEncoding属性时与 contentType属性中配置的编码一致,两者的优先级是:pageEncoding>contentType),才不会出现乱码

3MySQL中也需要设置编码为utf-8

4、提交表单时在doPost函数中添加request.setCharacterParameter("utf-8"); 语句。

五、比较alert("msg")、 confirm("msg")、 prompt("msg")

警告框:window.alert(str)alert(str)

确认框:answer = window.confirm(str)answer = confirm(str)

提示框:returnStr = window.prompt(targetQuestion,defaultString)

       或prompt(targetQuestion,defaultString)

alert()confirm()的最大区别是alert()没有返回值,confirm()的返回值有两种,一个是return false,一个是return true。当confirm()的对话框跳出时,点击确认,返回值就是true,点击取消,返回的是false

六、新建JSP页面

新建JSP页面时,选择JSP(Basic templates)

jsp页面的静态部分,如HTMLCSS标记等,用来完成页面布局和显示样式;jsp页面的动态部分,如脚本程序、jsp

JSP声明举例如下:

   synchronized void count() {number++;}

%>  //此段代码声明了一个变量number和一个方法count,它们可以在整个jsp页面的任何位置上使用

    

你是第个访问本站的客户

JSP内建对象有:

1、out:传送信息到客户端的浏览器

          eg1out.println("

Hello,JSP

");

          eg2out.println(i)    

2、request:包装客户端的请求信息;

3、response:响应客户端的请求;

4、session:客户端请求的一次会话。会话从客户端连接到服务器开始,直到与服务器断开连接为止,期间都可以访问session对象的属性和方法。

七、request对象、response对象

    request对象 : 客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例。

    response对象 : response对象包含了响应客户请求的有关信息,但在JSP中很少直接用到它。它是HttpServletResponse类的实例。

八、比较pagerequestsessionapplication的使用范围

在一个页面范围内:page

在一次服务器请求范围内:request

在一次会话范围内:session

在一个应用服务器范围内:application

document是js( ... )的对象,不是java( )的对象;

${...}取到的值是request范围内的值,跟request.getAttribute();效果一样。

之所以能取到值,是因为上面javascript中有定义,其实是存在page范围内的。

九、在JSP环境中配置使用FCKeditor

使用在线编辑器必不可少下述语句:

....

    FCKeditor oFCKeditor;

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

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

    oFCKeditor .setVaule("  ");

    out.println(oFCKeditor .create());

%>

十、MVC模式

当引入servlet后,由servlet完成控制的功能,同时jsp单纯地完成页面展示功能,这是MVC模式(Model-View-Controller:模型-视图-控制器)

采用jsp+javaBean+servlet模式设计:

1、一个index.jsp页面。例如用于显示留言簿内容,有一个表单用于提交留言簿内容;

2、一个servlet文件Operate.java。该文件接收表单提交的数据,一般进行三种处理:返回index.jsp所有留言信息;删除留言信息;插入留言信息。

3、一个封装了数据库操作的类DBOperate.java。该类的设计采用了singleton设计模式。

十一、Servlet配置

servlet/jsp Mapping URL : /servlet/add_servlet

File Path of web.xml : /项目名称/WebRoot/WEB-INF

十二、图片上传

    图片上传要实现的是:将图片上传到服务器保存到某个文件夹中,将图片名称放到数据库中,图片名称一般根据当前时间来重命名。详情见***

十三、JSP连接MySQL

DriverManager是管理JDBC驱动程序的接口,它通过getConnection方法获得Connection对象引用。Connection con = DriverManager.getConnection();

Statement是向数据库提交SQL语句并返回相应结果的工具。

ResultSet executeQuery(String sql) throws SQLException

Int executeUpdate(String sql) 返回发生改变的记录条数

Boolean execute(String sql)  判断是否执行成功

PreparedStatement接口继承Statement接口,当一条SQL语句需要稍加变化而反复执行时,通常采用PreparedStatement

十四、翻页功能



十五、error:Interger与int的转化

项目最后遇到的问题是Interger与int的转化,解决办法就是利用强制转换。

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

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.