jsp实例教程源码(jsp开发教程)

本文目录一览:

jsp登陆界面源代码

1、login.jsp文件

%@ page language=”java” contentType=”text/html; charset=GB18030″

pageEncoding=”GB18030″%

%@ page import=”java.util.*” %

!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”

html

head

title登录页面/title

/head

body

form name=”loginForm” method=”post” action=”judgeUser.jsp”

table

tr

td用户名:input type=”text” name=”userName” id=”userName”/td

/tr

tr

td密码:input type=”password” name=”password” id=”password”/td

/tr

tr

tdinput type=”submit” value=”登录” style=”background-color:pink” input

type=”reset” value=”重置” style=”background-color:red”/td

/tr

/table

/form

/body

/html

2、judge.jsp文件

%@ page language=”java” contentType=”text/html; charset=GB18030″

pageEncoding=”GB18030″%

%@ page import=”java.util.*” %

!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”

html

head

title身份验证/title

/head

body

%

request.setCharacterEncoding(“GB18030”);

String name = request.getParameter(“userName”);

String password = request.getParameter(“password”);

if(name.equals(“abc”) password.equals(“123”)) {

3、afterLogin.jsp文件

%

jsp:forward page=”afterLogin.jsp”

jsp:param name=”userName” value=”%=name%”/

/jsp:forward

%

}

else {

%

jsp:forward page=”login.jsp”/

%

}

%

/body

/html

%@ page language=”java” contentType=”text/html; charset=GB18030″

pageEncoding=”GB18030″%

!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”

html

head

title登录成功/title

/head

body

%

request.setCharacterEncoding(“GB18030”);

String name = request.getParameter(“userName”);

out.println(“欢迎你:” + name);

%

/body

/html

扩展资料:

java web登录界面源代码:

1、Data_uil.java文件

import java.sql.*;

public class Data_uil

{

public  Connection getConnection()

{

try{

Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);

}catch(ClassNotFoundException e)

{

e.printStackTrace();

}

String user=”***”;

String password=”***”;

String url=”jdbc:sqlserver://127.0.0.1:1433;DatabaseName=***”;

Connection con=null;

try{

con=DriverManager.getConnection(url,user,password);

}catch(SQLException e)

{

e.printStackTrace();

}

return con;

}

public  String selectPassword(String username)

{

Connection connection=getConnection();

String sql=”select *from login where username=?”;

PreparedStatement preparedStatement=null;

ResultSet result=null;

String password=null;

try{

preparedStatement=connection.prepareStatement(sql);

preparedStatement.setString(1,username);

result=preparedStatement.executeQuery();//可执行的     查询

if(result.next())

password=result.getString(“password”);

}catch(SQLException e){

e.printStackTrace();

}finally

{

close(preparedStatement);

close(result);

close(connection);

}

System.out.println(“找到的数据库密码为:”+password);

return password; 

}

public  void close (Connection con)

{

try{

if(con!=null)

{

con.close();

}

}catch(SQLException e)

{

e.printStackTrace();

}

}

public  void close (PreparedStatement preparedStatement)

{

try{

if(preparedStatement!=null)

{

preparedStatement.close();

}

}catch(SQLException e)

{

e.printStackTrace();

}

}

public  void close(ResultSet resultSet)

{

try{

if(resultSet!=null)

{

resultSet.close();

}

}catch(SQLException e)

{

e.printStackTrace();

}

}

}

2、login_check.jsp:文件

%@ page language=”java” contentType=”text/html; charset=utf-8″

pageEncoding=”utf-8″%

!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “”

html

head

meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″

title验证用户密码/title

/head

body

jsp:useBean id=”util” class=”util.Data_uil” scope=”page” /

%

String username=(String)request.getParameter(“username”);

String password=(String)request.getParameter(“password”);

if(username==null||””.equals(username))

{

out.print(“script language=’javaScript’ alert(‘用户名不能为空’);/script”);

response.setHeader(“refresh”, “0;url=user_login.jsp”);

}

else

{

System.out.println(“输入的用户名:”+username);

String passwordInDataBase=util.selectPassword(username);

System.out.println(“密码:”+passwordInDataBase);

if(passwordInDataBase==null||””.equals(passwordInDataBase))

{

out.print(“script language=’javaScript’ alert(‘用户名不存在’);/script”);

response.setHeader(“refresh”, “0;url=user_login.jsp”);

}

else if(passwordInDataBase.equals(password))

{

out.print(“script language=’javaScript’ alert(‘登录成功’);/script”);

response.setHeader(“refresh”, “0;url=loginSucces.jsp”);

}

else

{

out.print(“script language=’javaScript’ alert(‘密码错误’);/script”);

response.setHeader(“refresh”, “0;url=user_login.jsp”);

}

}

%

/body

/html

3、loginSucces.jsp文件

%@ page language=”java” contentType=”text/html; charset=utf-8″

pageEncoding=”utf-8″%

!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “”

html

head

meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″

titleInsert title here/title

/head

body

hr size=”10″ width=”26%” align=”left” color=”green”

font size=”6″ color=”red” 登录成功 /font

hr size=”10″ width=”26%” align=”left” color=”green”

/body

/html

4、user_login.jsp文件

%@ page language=”java” contentType=”text/html; charset=utf-8″

pageEncoding=”utf-8″%

!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “”

html

head

meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″

title登录界面/title

/head

body  background=”C:\Users\win8\workspace\Login\image\9dcbdc339e72a5663b5c289fb5573c13_10.jpg”

center

brbrbrbrbrbr

h1 style=”color:yellow”Login/h1

br

form name=”loginForm” action=”login_check.jsp” method=”post” 

table Border=”0″

tr

td账号/td

tdinput type=”text” name=”username”/td

/tr

tr

td密码/td

tdinput type=”password” name=”password”

/td

/tr

/table

br

input type=”submit” value=”登录” style=”color:#BC8F8F”

/form

/center

/body

/html

jsp源码的使用

你下载的是一个项目 应该是用SSH框架写的,因为看到hibernato 呵呵。

.sql文件应该是oracel数据库的建表和建存储过程的语句。

src目录下是java的类源码

webroot是jsp目录

其他是myelipse的配置文件和属性文件

jsp 中网站的首页源代码

这是最简单的一个例子,数据库要你自己建,用的是ACCESS

%@ page contentType=”text/html; charset=gb2312″ language=”java” import=”java.sql.*” errorPage=”” %

html

head

meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″

titleJSP连接Access数据库/title

style type=”text/css”

!–

.style1 {

font-size: 20px;

font-weight: bold;

}

/style

/headbody

div align=”center” class=”style1″JSP连接Access数据库/div

br

hr

p%

Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); //载入驱动程序类别

Connection con = DriverManager.getConnection(“jdbc:odbc:jspdata”); //建立数据库链接,jspdata为ODBC数据源名称

//建立Statement对象

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_READ_ONLY);

ResultSet rs = stmt.executeQuery(“select * from lyb”); //建立ResultSet(结果集)对象,并执行SQL语句

%

/p

p align=”center”NUMB1数据表中记录如下/p

table width=”640″ border=”1″ align=”center” bordercolor=”#7188e0″

tr bgcolor=”d1d1ff”

th width=”49″编号/th

th width=”90″姓名/th

th width=”126″E-mail/th

th width=”221″网站/th

th width=”80″QQ/th

/tr

%

while(rs.next())

{

%

tr bgcolor=”#f8f8f8″

th%= rs.getString(1) %/th

th%= rs.getString(2) %/th

th%= rs.getString(3) %/th

th bgcolor=”#f6f6f8″%= rs.getString(4) %/th

th%= rs.getString(5) %/th

/tr

%

}

rs.close();

stmt.close();

con.close();

%

/table

p align=”center”br

如果您能看到表格中的数据,说明连接数据库成功!/p

/body

/html

给定JSP程序源码如下:

这个问题其实就是相当于:

int count=1;

out.print(++count);

还是

out.print(count++);

a和d是正确的jsp输出语法,b和c只是做了自增,但是并没有输出。

a的输出是2

肯定就是选d了

jsp技术的验证码源代码?

实际当中很少用这种纯JSP的验证码技术,缺乏安全性,下面有一个这样的纯JSP的例,参考别人的,你可以看看。

纯数字验证码

在JSP页面body区域编写如下代码:

导入java.awt.*,java.awt.image.BufferedImage,javax.imageio.ImageIO包

%

   //验证码边框的长高

   int width = 60;

   int height = 20;

   //用RGB模式输出图像区域

   BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

   //定义画笔

   Graphics graph = image.getGraphics();

   //设置验证码框背景色0-255

   graph.setColor(new Color(200, 200, 200));

   //填充矩形

   graph.fillRect(0, 0, width, height);

   //产生1000-9999之间的随机数

   Random rnd = new Random();

   int rndNum = rnd.nextInt(8999) + 1000;

   //此处为何转换为String型的用int型的效果一样?

   String rndStr = String.valueOf(rndNum);

   session.setAttribute(“rndStr”, rndNum);

   //设置矩形区域中随机数及干扰点的颜色

   graph.setColor(Color.RED);

   //设置随机数的字体大小

   graph.setFont(new Font(“”,Font.PLAIN,20));

   //在已有的矩形区域中绘制随机数

   graph.drawString(rndStr, 8, 17);

   //随机产生100个干扰点

   for (int i = 0; i  100; i++)

   {

    int x = rnd.nextInt(width);

    int y = rnd.nextInt(height);

    //设置干扰点的位置长宽

    graph.drawOval(x, y, 1, 1);

   }

   //将图像输出到页面上

   ImageIO.write(image, “JPEG”, response.getOutputStream());

   //清空缓冲区

   out.clear();

   out = pageContext.pushBody();

  %

jsp源码怎么使用

个人建议:

使用eclipse或myeclipse导入整站源码。

在eclipse或myeclipse配置好tomcat和jdk,然后导入工程(整站源码),运行tomcat就OK了。

如果在你的源码里有很多的.java文件,你又只有单纯的tomcat + jdk,你就要一个个去编译.java文件了。有

eclipse或myeclipse的协助,就不用手工去编译了。

原创文章,作者:简单一点,如若转载,请注明出处:https://www.506064.com/n/129586.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
简单一点简单一点
上一篇 2024-10-03 23:26
下一篇 2024-10-03 23:26

相关推荐

  • MQTT使用教程

    MQTT是一种轻量级的消息传输协议,适用于物联网领域中的设备与云端、设备与设备之间的数据传输。本文将介绍使用MQTT实现设备与云端数据传输的方法和注意事项。 一、准备工作 在使用M…

    编程 2025-04-29
  • Python3.6.5下载安装教程

    Python是一种面向对象、解释型计算机程序语言。它是一门动态语言,因为它不会对程序员提前声明变量类型,而是在变量第一次赋值时自动识别该变量的类型。 Python3.6.5是Pyt…

    编程 2025-04-29
  • Deepin系统分区设置教程

    本教程将会详细介绍Deepin系统如何进行分区设置,分享多种方式让您了解如何规划您的硬盘。 一、分区的基本知识 在进行Deepin系统分区设置之前,我们需要了解一些基本分区概念。 …

    编程 2025-04-29
  • 写代码新手教程

    本文将从语言选择、学习方法、编码规范以及常见问题解答等多个方面,为编程新手提供实用、简明的教程。 一、语言选择 作为编程新手,选择一门编程语言是很关键的一步。以下是几个有代表性的编…

    编程 2025-04-29
  • 云智直聘 源码分析

    本文将会对云智直聘的源码进行分析,包括前端页面和后端代码,帮助读者了解其架构、技术实现以及对一些常见的问题进行解决。通过本文的阅读,读者将会了解到云智直聘的特点、优势以及不足之处,…

    编程 2025-04-29
  • Qt雷达探测教程

    本文主要介绍如何使用Qt开发雷达探测程序,并展示一个简单的雷达探测示例。 一、环境准备 在开始本教程之前,需要确保你的开发环境已经安装Qt和Qt Creator。如果没有安装,可以…

    编程 2025-04-29
  • 猿编程python免费全套教程400集

    想要学习Python编程吗?猿编程python免费全套教程400集是一个不错的选择!下面我们来详细了解一下这个教程。 一、课程内容 猿编程python免费全套教程400集包含了从P…

    编程 2025-04-29
  • Python烟花教程

    Python烟花代码在近年来越来越受到人们的欢迎,因为它可以让我们在终端里玩烟花,不仅具有视觉美感,还可以通过代码实现动画和音效。本教程将详细介绍Python烟花代码的实现原理和模…

    编程 2025-04-29
  • 使用Snare服务收集日志:完整教程

    本教程将介绍如何使用Snare服务收集Windows服务器上的日志,并将其发送到远程服务器进行集中管理。 一、安装和配置Snare 1、下载Snare安装程序并安装。 https:…

    编程 2025-04-29
  • Python画K线教程

    本教程将从以下几个方面详细介绍Python画K线的方法及技巧,包括数据处理、图表绘制、基本设置等等。 一、数据处理 1、获取数据 在Python中可以使用Pandas库获取K线数据…

    编程 2025-04-28

发表回复

登录后才能评论