现在的位置: 首页 > 综合 > 正文

jsp登陆界面如何完成登陆

2019年05月13日 ⁄ 综合 ⁄ 共 1209字 ⁄ 字号 评论关闭
1.获取前台用户名密码(id,code);
2.读取后台用户名密码(yhm,mm);
现在想通过对比完成登陆操作 请问这部分代码应该怎么写呢(最好带说明)

登录login.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%>">
    <title>My JSP 'login.jsp' starting page</title>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  	<form name="loginForm" action="loginAction.jsp" method="post">
	  	用户名:<input type="text" name="username"/><br/>
	   	密码:<input type="text" name="password"/><br/>
	   <input type="submit" value="提交"/>
	   <input type="reset" value="重置"/>
  	</form>
  </body>
</html>

处理表单loginAction.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	String username=request.getParameter("username");
	String password=request.getParameter("password");
	if(username.equals("admin")&&password.equals("admin")){	//这里是模拟,实际和数据库打交道
		response.sendRedirect("index.jsp");//跳转到你要的界面
	}else{
		response.sendRedirect("login.jsp");
	}
%>

抱歉!评论已关闭.