search
HomeDatabaseMysql TutorialJava Servlet及Cookie的使用 _MySQL

Java Servlet及Cookie的使用 _MySQL

Jun 01, 2016 pm 02:09 PM
cookiedosuseCanTable of contentswindow

Cookieservlet

    本文介绍了Java Servlet编程所需的软件及环境配置。只要你有一台安装Windows 95/98了的PC机,便可以按照本文的步骤开发Servlet程序了。本文同时给出了通过Java Servlet向用户的硬盘写入和读取Cookie的方法及例程。通过它可以实现网上常见的个性化网页、网上购物篮、密码验证等。


   Java Servlet是运行于Web服务器上的Java代码,它可以接受用户请求,进行相应的处理,并向用户提供反馈。其作用类似于CGI程序,可以实现网页中很多交互式效果,但比CGI程序效率更高。Cookies是用户访问Web服务器时由Web服务器写入用户计算机特定目录的一小段信息, Java Servlet中提供了Cookie类,可以对Cookie进行操作。在特定时候将Cookie写入用户计算机,在需要时可再取出来使用。

   1.软件下载

   PC机,安装Windows 95/98,具有IP地址(如果没有可以随便配一个)。开发软件有两个:JDK1.3和JSWDK1.0.1。


   到http://java.sun.com,点击"Products & APIs”链接,可以点击下载"JavaTM 2 SDK, Standard Edition, v 1.3”。下载后的文件安装到你的计算机上。

   JSWDK1.0.1只有763,414 bytes,可从在http://java.sun.com/products/jsp/download.html下载。下载下来的jswdk1_0_1-win.zip用Winzip软件解压缩至某个目录,如:d:app,该目录下将自动建立一个子目录:jswdk-1.0.1。这时JSWDK 1.0.1便已经安装在d:appjswdk-1.0.1目录下了。

   2.启动JSWDK 1.0.1

   打开一个DOS窗口,如下图点击窗口左上角DOS图标,选择属性菜单,在接着出现的窗口中点击"内存”,在"初始环境”后的下拉菜单中将"自动”改为2816,点击"exit”按钮退出窗口,再重新进入DOS窗口。该设置只需要做一次。

   在该DOS窗口中运行如下DOS命令设置好环境变量:

   set CLASSPATH=c:jdk1.3bin;.

   set path=c:jdk1.3bin;c:windows;c:windowscommand

   如果你的JDK 1.3和Windows操作系统安装在其他目录,DOS命令中的目录名称应作相应修改。

   然后在该DOS窗口中用CD命令进入JSWDK 1.0.1安装目录(如d:appjswdk-1.0.1)运行startserver.bat即可。

   注意:

   对于JDK1.3,即本文所述的环境,需修改startserver.bat,将源文件中的

   start java com.sun.web.shell.Startup %1 %2 %3 %4 %5 %6 %7 %8 %9

   rem java com.sun.web.shell.Startup %1 %2 %3 %4 %5 %6 %7 %8 %9

   改为:

   rem start java com.sun.web.shell.Startup %1 %2 %3 %4 %5 %6 %7 %8 %9

   java com.sun.web.shell.Startup %1 %2 %3 %4 %5 %6 %7 %8 %9

   若使用的是老版本的JDK1.2,不需要修改startserver.bat,执行后会出现另一个DOS窗口。

   运行后显示一串字符串,最后显示endpoint created: localhost/127.0.0.1:8080。表明正常启动完毕。但它不支持数据库中文字段和中文值的查询。

   打开一个浏览器,输入:http://你的机器IP地址:8080,这时浏览器中显示出缺省的页面,在该页面中可查看Servlet例子。
   Java Servlet中提供了Cookie类,其构造器有两个参数,分别代表Cookie的名字和值。Cookie类中提供了各种方法设置Cookie的属性,如通过setMaxAge( )方法可以设置Cookie的生存时间。若生存时间为负值,代表浏览器关闭Cookie即消失。生存时间为0,代表删除Cookie,生存时间为正数,代表Cookie存在多少秒。

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
Explain the role of InnoDB redo logs and undo logs.Explain the role of InnoDB redo logs and undo logs.Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?Apr 15, 2025 am 12:15 AM

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

What is the Using temporary status in EXPLAIN and how to avoid it?What is the Using temporary status in EXPLAIN and how to avoid it?Apr 15, 2025 am 12:14 AM

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Apr 15, 2025 am 12:11 AM

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL vs. Other Databases: Comparing the OptionsMySQL vs. Other Databases: Comparing the OptionsApr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

How does MySQL index cardinality affect query performance?How does MySQL index cardinality affect query performance?Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL: Resources and Tutorials for New UsersMySQL: Resources and Tutorials for New UsersApr 14, 2025 am 12:16 AM

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

Real-World MySQL: Examples and Use CasesReal-World MySQL: Examples and Use CasesApr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor