几则JSP入门知识总结_MySQL
从去年9月份,我就开始着手学JSP,以前也只有一点程序的意识,一路上摸索过来,经过了很多磨难,终于有一天,我就像一个旱鸭子学会游泳一样,心里无比高兴,熬了几天夜,终于写成了这个纯JSP的文章发布程序。
相信下面的几则小知识对向我这样水平的菜鸟有一定的帮助!
==============================================================================
1.传递表单参数:
String name = new String(request.getParameter("name"));
2.数据库连接:
~~MYSQL
//设置数据库的URL
String url = "jdbc:mysql://localhost:3306/jspsky";
try
//加载驱动程序
Class.forname("org.gjt.mm.mysql.Driver").newInstance();
//建立连接
java.sql.Connection connection = java.sql.DriverManager.getConnection(url);
java.sql.Statement statement = connection.createStatement();
//SQL语句
String sqlStringi ="insert into commu(name,tel,mobile,oicq,email)values(‘"+name+"’,‘"+tel+"’,‘"+mobile+"’,‘"+oicq+"’,‘"+email+"’)";
//运行SQL语句,并建立结果集
java.sql.ResultSet rsi = statement.executeQuery(sqlStringi);
//在屏幕上输出库中的内容
while(rss.next())
{
String a_name = rss.getString(1);
out.println(a_name);
{}
//关闭连接
connection.close();
}
//捕捉异常
catch(java.sql.SQLException e)
out.println(e.getMessage());
{}
catch(ClassNotFoundException e)
out.println(e.getMessage());
{}
~~DB2
//定义数据库的URL
String url = "jdbc:db2:portal";
try
//加载驱动程序
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
//建立连接,
java.sql.Connection connection = java.sql.DriverManager.getConnection(url,"user","password");
java.sql.Statement statement = connection.createStatement();
//SQL语句
String sqlString = "select * from client";
//执行SQL语句
java.sql.ResultSet rs = statement.executeQuery(sqlString);
//在屏幕上显示所连表中的内容
while(rs.next())
{
String name = rs.getString(1);
out.println(name);
{}
//关闭连接
connection.close();
}
//捕捉异常
catch(java.sql.SQLException e)
out.println(e.getMessage());
{}
catch(ClassNotFoundException e)
out.println(e.getMessage());
{}
3.文件操作
~~将一个字符串写到一个指定的文件中,如果该文件不存在,则新建一个文件,并完成写入;如果存在,则用此字符串覆盖原文件的所有内容
import java.io.*;
String str = "print me 雪峰!";
//定义好打印的目标文件名
//取得当前主机存放WEB页面的绝对路径
String hostdir = System.getProperty("user.dir");
//取得当前主机所采用的路径分隔符
String fileBar = System.getProperty("file.separator");
//书写完整的目标文件存放路径
String nameOfFile=hostdir+fileBar+"test.html";
try
//实例化一个文件输出流对象
FileOutputStream afile = new FileOutputStream(nameOfFile);
//将文件输出流,创建一个打印输出流对象
PrintWriter pw = new PrintWriter(afile);
pw.println(str);
//clean up
pw.close();
{}
catch(IOException e)
out.println(e.getMessage());
{}
~~列出指定目录下的文件列表
import java.io.*;
String cdur = System.getProperty("user.dir");
String fileBar = System.getProperty("file.separator");
String mydir =cdur+fileBar+"doc"+fileBar+"jspsky";
File my = new File(mydir);
String d[] = my.list();
int i;
int l=d.length;
for(i=0;i out.print(d[i]);
{}
4.计数器
Integer count = null;
synchronized (application)
count =(Integer) application.getAttribute("d");
if (count ==null)
count =new Integer("0");
count = new Integer(count.intValue()+1);
application.setAttribute("d",count);
{}
out.println(count);
// 首先定义一个整形对象,并初始化为:NULL,
// 取回APPLICATION对像的属性D的值,并强制转化为整形对象,赋给COUNT
// 判断COUNT是否为空,为空时,将O赋给COUNT对象,
// 否则,通过COUNT。INTVALUE()方法,实现COUNT对象加1,并赋值给COUNT
// 最后,将COUNT对象保存在APPLICATION对象的D变量中。
+++++++++++++++++++
下一步学习重点
文件的删除
文件内容的修改
图片的上传
邮件列表
JAVABEANS
EJB
XML
JAVASCRIPT
对数据库的操作及维护
了解商业项目开发流程
实例练习
留言板
聊天室
发送邮件
新闻系统
截取网页内容
购物车
多做练习,在实践中不断熟悉JAVA包的使用!

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

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

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

Diffusion can not only imitate better, but also "create". The diffusion model (DiffusionModel) is an image generation model. Compared with the well-known algorithms such as GAN and VAE in the field of AI, the diffusion model takes a different approach. Its main idea is a process of first adding noise to the image and then gradually denoising it. How to denoise and restore the original image is the core part of the algorithm. The final algorithm is able to generate an image from a random noisy image. In recent years, the phenomenal growth of generative AI has enabled many exciting applications in text-to-image generation, video generation, and more. The basic principle behind these generative tools is the concept of diffusion, a special sampling mechanism that overcomes the limitations of previous methods.

Kimi: In just one sentence, in just ten seconds, a PPT will be ready. PPT is so annoying! To hold a meeting, you need to have a PPT; to write a weekly report, you need to have a PPT; to make an investment, you need to show a PPT; even when you accuse someone of cheating, you have to send a PPT. College is more like studying a PPT major. You watch PPT in class and do PPT after class. Perhaps, when Dennis Austin invented PPT 37 years ago, he did not expect that one day PPT would become so widespread. Talking about our hard experience of making PPT brings tears to our eyes. "It took three months to make a PPT of more than 20 pages, and I revised it dozens of times. I felt like vomiting when I saw the PPT." "At my peak, I did five PPTs a day, and even my breathing was PPT." If you have an impromptu meeting, you should do it

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

Quark Netdisk and Baidu Netdisk are currently the most commonly used Netdisk software for storing files. If you want to save the files in Quark Netdisk to Baidu Netdisk, how do you do it? In this issue, the editor has compiled the tutorial steps for transferring files from Quark Network Disk computer to Baidu Network Disk. Let’s take a look at how to operate it. How to save Quark network disk files to Baidu network disk? To transfer files from Quark Network Disk to Baidu Network Disk, you first need to download the required files from Quark Network Disk, then select the target folder in the Baidu Network Disk client and open it. Then, drag and drop the files downloaded from Quark Cloud Disk into the folder opened by the Baidu Cloud Disk client, or use the upload function to add the files to Baidu Cloud Disk. Make sure to check whether the file was successfully transferred in Baidu Cloud Disk after the upload is completed. That's it

Recently, many netizens have asked the editor, what is the file hiberfil.sys? Can hiberfil.sys take up a lot of C drive space and be deleted? The editor can tell you that the hiberfil.sys file can be deleted. Let’s take a look at the details below. hiberfil.sys is a hidden file in the Windows system and also a system hibernation file. It is usually stored in the root directory of the C drive, and its size is equivalent to the size of the system's installed memory. This file is used when the computer is hibernated and contains the memory data of the current system so that it can be quickly restored to the previous state during recovery. Since its size is equal to the memory capacity, it may take up a larger amount of hard drive space. hiber

In the early morning of June 20th, Beijing time, CVPR2024, the top international computer vision conference held in Seattle, officially announced the best paper and other awards. This year, a total of 10 papers won awards, including 2 best papers and 2 best student papers. In addition, there were 2 best paper nominations and 4 best student paper nominations. The top conference in the field of computer vision (CV) is CVPR, which attracts a large number of research institutions and universities every year. According to statistics, a total of 11,532 papers were submitted this year, and 2,719 were accepted, with an acceptance rate of 23.6%. According to Georgia Institute of Technology’s statistical analysis of CVPR2024 data, from the perspective of research topics, the largest number of papers is image and video synthesis and generation (Imageandvideosyn

We know that LLM is trained on large-scale computer clusters using massive data. This site has introduced many methods and technologies used to assist and improve the LLM training process. Today, what we want to share is an article that goes deep into the underlying technology and introduces how to turn a bunch of "bare metals" without even an operating system into a computer cluster for training LLM. This article comes from Imbue, an AI startup that strives to achieve general intelligence by understanding how machines think. Of course, turning a bunch of "bare metal" without an operating system into a computer cluster for training LLM is not an easy process, full of exploration and trial and error, but Imbue finally successfully trained an LLM with 70 billion parameters. and in the process accumulate

Editor of the Machine Power Report: Yang Wen The wave of artificial intelligence represented by large models and AIGC has been quietly changing the way we live and work, but most people still don’t know how to use it. Therefore, we have launched the "AI in Use" column to introduce in detail how to use AI through intuitive, interesting and concise artificial intelligence use cases and stimulate everyone's thinking. We also welcome readers to submit innovative, hands-on use cases. Video link: https://mp.weixin.qq.com/s/2hX_i7li3RqdE4u016yGhQ Recently, the life vlog of a girl living alone became popular on Xiaohongshu. An illustration-style animation, coupled with a few healing words, can be easily picked up in just a few days.
