首页 > 编程知识 正文

jsp大学应用教程源代码(jsp应用开发与实践源代码)

时间:2023-12-17 21:42:41 阅读:316773 作者:ZOBK

本文目录一览:

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课本源代码

实现会员信息管理功能,包括增加会员信息,修改会员信息,删除会员信息,查询(精确和模糊)会员信息功能。

JSP的源代码写在哪?

jsp文件是一个可以对页面和java代码都能操作的页面,可以有html标签和java代码嵌套。java文件是你的类文件,只能有java代码,

服务器执行jsp文件的时候其实本质是执行的java文件,我们把这种特殊的java文件称作servlet,他具有一定固有的结构。执行过程是这样的

首先我们要知道servlet是个什么东西,你可以理解为他是一个java

web需要遵守的规范,他其实是一个接口interface,我们常用的tomcat就是一个servlet容器,他实现了servlet这个接口。所以我们的服务器Tomcat处理web请求的时候就是把jsp首先翻译转换成一个servlet文件(后缀是java的文件,只是拥有特定的格式所以叫做servlet),然后服务器执行这个servlet文件,根据servlet里的方法调用其他的java文件,根据不同的需要各种java文件定义各种不同的类和功能,最终servlet执行结束用输出流打印一个htm文件格式输出到页面,浏览器识别这个htm显示出来,所以我们浏览器显示的并不是jsp而是jsp翻译成servlet运行后输出的htm

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:Userswin8workspaceLoginimage9dcbdc339e72a5663b5c289fb5573c13_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中怎么实现多项选择题,可以给以下源代码,

你说的多项选择题,我是不是可以理解成多选??

多选的实现是这样的:

第一: 必须将多选框放到form里面。

第二: 然后name属性完全一样,value不相同。这样当你提交到Action中的时候,只需要使用request对象获取toselect的值就行了。

第三: 获取值:request.getParameterValues("toselect"),就会将选中的多选框里面的value获取,并且返回一个String[]数组,这个数组里面就有你想要的值:即选中的值

html

body

form

input type = "checkbox" value = "A" name = "toselect"/A

input type = "checkbox" value = "B" name = "toselect"/B

input type = "checkbox" value = "C" name = "toselect"/C

input type = "checkbox" value = "D" name = "toselect"/D

/form

/body

/html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。