jsp登录界面代码(jsp登录界面代码连接数据库)
admin 发布:2022-12-19 03:28 121
本篇文章给大家谈谈jsp登录界面代码,以及jsp登录界面代码连接数据库对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
求大神写一下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页面的全部程序代码
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.输入界面:输入用户名和密码。2.处理界面:获取提交过来的数据(用户名和密码),然后进行验证。 然后填写正确时,跳转成功的界面;不正确时,跳转失败的界面。3.创建成功界面与失败界面。你看这样能理解吗? 追问: 可以理解,但是我不会写代码。 回答: 那我给你先写一个简单的把。等会啊。 补充: 登录界面:%@ page language="java" pageEncoding="GBK"%htmlheadtitle登录界面/title/headbodydiv align="center" form action="validate.jsp" method="post" 用户名:input type="text" name="myName"br 密码:input type="password" name="myPass"br input type="submit" value="登录"/form/div/body/html登录验证界面:%@ page language="java" pageEncoding="GBK"%%//处理中文乱码 request.setCharacterEncoding("GBK"); //获取提交的元素 String pass=request.getParameter("myPass");//业务处理if("admin".equals(name) "admin".equals(pass)){response.sendRedirect("yes.jsp");}else{response.sendRedirect("no.jsp");}%成功界面:%@ page language="java" pageEncoding="GBK"%htmlheadtitle成功界面/title/headbody登录成功!/body/html
JSP编写一个登陆界面
1、首先准备Dreamweaver8软件,解压安装。如下图所示:这件点击安装程序,然后输入序列号就可以了。
2、在安装软件时候,我们可以看到是否关联【jsp文件】。
3、安装好了软件以后,我们打开Dreamweaver8软件。点击菜单上的【文件】——【新建】。
4、弹出【新建文档】——【动态页】——【jsp】——【创建】。
5、点击【拆分】,在【body】标签下面输入:% out.println("Hello World!"); %。
6、然后按快捷键【ctrl+s】保存jsp文件。保存类型jps;。
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登录界面代码和jsp登录界面代码连接数据库的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:二叉树代码(层序遍历二叉树代码)
- 下一篇:jsp网页模板源代码(jsp 模板)
相关推荐
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接