Table of Contents
Hello,JSP
Home Database Mysql Tutorial JSP+MySQL+MyEclipse+JavaScript项目开发

JSP+MySQL+MyEclipse+JavaScript项目开发

Jun 07, 2016 pm 03:47 PM

一、已知有一个建好的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

十四、翻页功能

Copy after login

十五、error:Interger与int的转化

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

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

Statement of this Website
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

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1257
29
C# Tutorial
1231
24
When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

Can mysql and mariadb coexist Can mysql and mariadb coexist Apr 08, 2025 pm 02:27 PM

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

RDS MySQL integration with Redshift zero ETL RDS MySQL integration with Redshift zero ETL Apr 08, 2025 pm 07:06 PM

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Laravel Eloquent ORM in Bangla partial model search) Laravel Eloquent ORM in Bangla partial model search) Apr 08, 2025 pm 02:06 PM

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

See all articles