jsp登录界面代码(jsp登陆界面代码)
admin 发布:2022-12-20 00:18 194
本篇文章给大家谈谈jsp登录界面代码,以及jsp登陆界面代码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、JSP作业,求大神写代码!编制一个简单的登录界面。
- 2、编写用户注册于登录的JSP页面的全部程序代码
- 3、求大神写一下jsp的简单的注册界面代码。
- 4、jsp实现简单的登录界面
- 5、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.需要一个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实现简单的登录界面
index.jsp是本页面:
html
body
form action=manager.jsp name=form1 method=post
input type="text" name=name input type="password" name=password
input type="submit" value="登录" name="submit" 管理
/body
managet.jsp是要登录的页面:
%String name=request.getParameter("name");
String password=request.getParameter("password");
if(name=="cxh" password=="11011")
{
%
jsp:forward page="manager.jsp" /
%
}
else{ %
jsp:forward page="index.jsp" /
%}
%
这样才是提交嘛~~~你试试~
JSP编写一个登陆界面
1、首先准备Dreamweaver8软件,解压安装。如下图所示:这件点击安装程序,然后输入序列号就可以了。
2、在安装软件时候,我们可以看到是否关联【jsp文件】。
3、安装好了软件以后,我们打开Dreamweaver8软件。点击菜单上的【文件】——【新建】。
4、弹出【新建文档】——【动态页】——【jsp】——【创建】。
5、点击【拆分】,在【body】标签下面输入:% out.println("Hello World!"); %。
6、然后按快捷键【ctrl+s】保存jsp文件。保存类型jps;。
关于jsp登录界面代码和jsp登陆界面代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:dwr源代码(dw编程代码大全)
- 下一篇:页面刷新代码(页面自动刷新代码)
相关推荐
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接