jsp简单的登录页面代码怎么写(jsp编写登录页面)
admin 发布:2022-12-19 19:28 145
今天给各位分享jsp简单的登录页面代码怎么写的知识,其中也会对jsp编写登录页面进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
JSP作业,求大神写代码!编制一个简单的登录界面。
第一个页面命名:Login.html
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
html
head
titleLogin.html/title
meta http-equiv="keywords" content="keyword1,keyword2,keyword3"
meta http-equiv="description" content="this is my page"
meta http-equiv="content-type" content="text/html; charset=UTF-8"
!--link rel="stylesheet" type="text/css" href="./styles.css"--
/head
body
brbrbrbrbr
form method="post" action="checkLogin.jsp"
table align="center" width="300"
tr
td用户名:/td
tdinput type="text" name="username" size="20"/td
/tr
tr
td密 码:/td
tdinput type="password" name="password" size="20"/td
/tr
tr
td colspan="2" align="center"
input type="submit" value="登录"
input type="reset" value="取消"
/td
/tr
/table
/form
/body
/html
第二个页面命名:checkLogin.jsp
%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%
%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
html
head
base href="%=basePath%"
titleMy JSP 'checkLogin.jsp' starting page/title
meta http-equiv="pragma" content="no-cache"
meta http-equiv="cache-control" content="no-cache"
meta http-equiv="expires" content="0"
meta http-equiv="keywords" content="keyword1,keyword2,keyword3"
meta http-equiv="description" content="This is my page"
!--
link rel="stylesheet" type="text/css" href="styles.css"
--
/head
body
% String username,password;
request.setCharacterEncoding("utf-8");
username=request.getParameter("username");
password=request.getParameter("password");
if(username!=nullpassword!=null){
out.println("h2用户名:font color='blue'b"+username+"/b/fontbrh2");
out.println("h2密码:font color='blue'b"+password+"/b/fonth2");
}
else{
out.println("h2请填写用户名和密码!/h2br3秒钟后,自动跳转到登入页面...");
response.setHeader("refresh","3;url=Login.html");
}
%
/body
/html
编写用户注册于登录的JSP页面的全部程序代码
3个jsp文件,第一个是login.jsp,第二个是judge.jsp,第三个是afterLogin.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
%@ 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")) {
%
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
JSP编写一个登陆界面
1、首先准备Dreamweaver8软件,解压安装。如下图所示:这件点击安装程序,然后输入序列号就可以了。
2、在安装软件时候,我们可以看到是否关联【jsp文件】。
3、安装好了软件以后,我们打开Dreamweaver8软件。点击菜单上的【文件】——【新建】。
4、弹出【新建文档】——【动态页】——【jsp】——【创建】。
5、点击【拆分】,在【body】标签下面输入:% out.println("Hello World!"); %。
6、然后按快捷键【ctrl+s】保存jsp文件。保存类型jps;。
求大神写一下jsp的简单的注册界面代码。
1.需要一个jsp页面:
//login.jsp核心代码:
form action="${pageContext.request.contextPath}/servlet/UserServlet" method="post"
input type="text" name="loginname" /input type="password" name="password"/
input type="submit" value="登录"/
/form
2.需要一个servlet来验证登录信息
//UserServlet 核心代码
class UserServlet extends HttpServlet{
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
private void process(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
String loginname = request.getParameter("loginname");
String password = request.getParameter("password");
//创建一个service来处理业务逻辑(包括查询数据库操作)
UserService service = new UserService();
boolean bool = service.validateUser(loginname,password);
if(!bool){
pw.println("用户名或密码错误");
}else{
pw.println("登录成功");
}
}
3.需要一个service处理业务逻辑(包括查询数据库操作)
//UserService 核心代码
public class UserService{
/**
*查询数据库验证用户是否存在,返回boolean
*/
public boolean validateUser(String loginname,String password){
boolean bool = false;
Connection conn = null;
PreparedStatement ps = null;
//这里以mysql为例
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
String sql = "select login_name,pass_word from t_user where login_name=? and pass_word=?";
ps = conn.prepareStatement(sql);
ps.setString(0, loginname);
ps.setString(1, password);
ResultSet rs = ps.executeQuery();
if(rs.next()){
bool = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if(conn != null){
conn.close();
conn = null;
}
if(ps != null){
ps.close();
ps = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return bool;
}
}
jsp简单的登录页面代码怎么写的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于jsp编写登录页面、jsp简单的登录页面代码怎么写的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 04-29web课程设计源代码(网页设计与制作课程代码)[20240429更新]
- 04-29在哪输入代码可以出来表情(输入法表情代码)[20240429更新]
- 04-29进销存软件代码(进销存软件是什么软件)[20240429更新]
- 04-29评论发布代码(评论框代码)[20240429更新]
- 04-29班级管理系统jsp代码的简单介绍[20240429更新]
- 04-29代码高亮(代码高亮是什么意思)[20240429更新]
- 04-29jsp收费系统源代码的简单介绍[20240429更新]
- 04-29文字特效js代码(文字效果代码)[20240429更新]
- 04-29phpqq代码(免费代码)[20240429更新]
- 04-29css广告代码生成器(广告设计生成器)[20240429更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接