Java Servlet及Cookie的使用 _MySQL
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存在多少秒。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to set Google Chrome to open a new window every time? Vicious users like to use Google Chrome for work or study. This browser is safe, fast, and convenient. Different users have different preferences for using browsers. Some users like to open Google Chrome as a new window to facilitate quick searches. , so how to set it up. Next, the editor will bring you a tutorial on setting up a new window every time you open Google Chrome. Friends who are interested can come and learn it. Tutorial on setting up a new window every time Google Chrome opens 1. Double-click Google Chrome on your computer desktop to open it, then click on the [three dots] icon in the upper right corner. 2. Find the [Settings] option and enter the page (as shown in the picture). 3. Go to Google Chrome

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

Apple rolled out the iOS 17.4 update on Tuesday, bringing a slew of new features and fixes to iPhones. The update includes new emojis, and EU users will also be able to download them from other app stores. In addition, the update also strengthens the control of iPhone security and introduces more "Stolen Device Protection" setting options to provide users with more choices and protection. "iOS17.3 introduces the "Stolen Device Protection" function for the first time, adding extra security to users' sensitive information. When the user is away from home and other familiar places, this function requires the user to enter biometric information for the first time, and after one hour You must enter information again to access and change certain data, such as changing your Apple ID password or turning off stolen device protection.

With the rapid development of network technology, our lives have also been greatly facilitated, one of which is the ability to download and share various resources through the network. In the process of downloading resources, magnet links have become a very common and convenient download method. So, how to use Thunder magnet links? Below, I will give you a detailed introduction. Xunlei is a very popular download tool that supports a variety of download methods, including magnet links. A magnet link can be understood as a download address through which we can obtain relevant information about resources.
