当前位置:首页 > 代码 > 正文

jsp网站全套代码(jsp网站开发详解)

admin 发布:2022-12-19 19:45 106


今天给各位分享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程序代码

%@ page language="java" import="java.util.*" errorPage="error.jsp" pageEncoding="UTF-8"%

% request.setCharacterEncoding("GBK");%

html

head

title动作处理页面/title

/head

body background="C:\tp\yy.JPG"

font color=yellow

centerbrh2

jsp:useBean id="loginbean" class="com.login.LoginBean"/jsp:useBean //使用jsp:useBean标签调用LoginBean.java,class指明JavaBean位置

jsp:setProperty name="loginbean" property="*" ///设置LoginBean的属性值

%out.println("用户号为:"+loginbean.getUserid()+"brbr"); 输出loginbean里面getUserid的值

if (loginbean.getUserid()==null){ //如果用户名为空

throw new Exception("尊敬的用户:系统登录页面中的用户名不能为空,请输入用户号!");

}

if (loginbean.getPsw()==null){ //如果密码为空

throw new Exception("尊敬的用户:系统登录页面中的密码不能为空,请输入密码!");

}

if (loginbean.getPsw().equalsIgnoreCase("neusoft")) //如果JavaBean的密码和输入密码相同

{

String puserid = request.getParameter("userid"); //获得此用户ID

Cookie cookies[] = request.getCookies();

//如果是上一步提交过来的,则更新Cookie的值

if(puserid != null) {

Cookie c = new Cookie("userid", puserid);

c.setMaxAge(60*60*24*30); //Cookie的有效期为1个月setMaxAge()是Cookie 的一个方法

器单位为秒

60*60*24*30等与30天*24小时*60分*60秒==结果就为1个月的秒数

response.addCookie(c);

}

session.setAttribute("login","ok");

session.setMaxInactiveInterval(-1);

%

jsp:forward page="success.jsp" / //跳转至success.jsp

%

}

else { //如果密码不正确则执行

out.println("对不起,密码输入错误!您此次系统登陆失败!请重新输入密码!brbr");

out.println("A href=login.jsp返回/Abr");

}

%

h2

br

hr

/font

/body

/html

答题完毕

JSP代码分享

jsp:include page="/jstl/header.jsp" /

center

h1

Modify userinfo

/h1

form method="post"

action="${pageContext.request.contextPath}/filter/modifyuserinfo.do"

input type="hidden" name="operation" value="modifyuserinfo" /

table border="1"

tr

td

username:

/td

td

input readonly="true" type="text" name="username"

value="${isLogined.username}" /

/td

/tr

tr

td

new password:

/td

td

input type="password" name="password" id="pp"

value="${isLogined.password}" /

/td

/tr

tr

td

confirm pw:

/td

td

input type="password" name="password2" id="pp2"

value="${isLogined.password}" /

/td

/tr

tr

td

realname:

/td

td

input type="text" name="realname" value="${isLogined.realname}" /

/td

/tr

tr

td

address:

/td

td

input type="text" name="address" value="${isLogined.address}" /

/td

/tr

tr

td

zipCode:

/td

td

input type="text" name="zipcode" value="${isLogined.zipcode}" /

/td

/tr

tr

td

phone:

/td

td

input type="text" name="phone" value="${isLogined.phone}" /

/td

/tr

tr

td colspan="2" align="center"

input type="submit" value="Save" /

/td

/tr

/table

/form

/center

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代码,题目如下:

rect.jsp

%@ page language="java" pageEncoding="utf-8"%

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

/head

body

form action="com.jsp" method="post"

请输入正方形的边长: input type="text" name="length" width="100px"

br/ br/

input type="submit" value="submit"

/form

/body

/html

com.jsp

%@ page language="java" pageEncoding="utf-8"%

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

/head

body

%

String length=request.getParameter("length");

float s=0;

try{

s=Float.parseFloat(length);

}

catch (Exception e)

{

out.print("请输入有效数值brbr");

s=0;

}

%

正方形周长为: %=4*s %br/

正方形面积为: %=s*s %br/

/body

/html

关于jsp网站全套代码和jsp网站开发详解的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/21273.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载