前段jsp代码(JSP前端)

发布时间:2023-12-08

前段jsp代码(JSP前端)

更新:<time datetime="2022-11-11 13:43">2022-11-11 13:43</time>

本文目录一览:

1、jsp登陆界面源代码
2、jsp页面的代码由哪两部分组成
3、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>
<td><input 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")) {
%>
<jsp:forward page="afterLogin.jsp">
<jsp:param name="userName" value="<%=name%>"/>
</jsp:forward>
<%
} else {
%>
<jsp:forward page="login.jsp"/>
<%
}
%>
</body>
</html>

3、afterLogin.jsp文件

<%@ 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">
<title>Insert 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>
<br><br><br><br><br><br>
<h1 style="color:yellow">Login</h1>
<br>
<form name="loginForm" action="login_check.jsp" method="post">
<table Border="0">
<tr>
<td>账号</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" name="password"/></td>
</tr>
</table>
<br>
<input type="submit" value="登录" style="color:#BC8F8F"/>
</form>
</center>
</body>
</html>

jsp页面的代码由哪两部分组成

  1. JSP(全称JavaServer Pages)是由Sun Microsystems公司主导创建的一种动态网页技术标准。JSP部署于网络服务器上,可以响应客户端发送的请求,并根据请求内容动态地生成HTML、XML或其他格式文档的Web网页,然后返回给请求者。JSP技术以Java语言作为脚本语言,为用户的HTTP请求提供服务,并能与服务器上的其它Java程序共同处理复杂的业务需求。
  2. 至于JSP页面代码由哪两部分组成,这个问题问的就不专业,没有这样的说法,简单来说页面代码可以分为HTML和JSP部分,布局上可以分为页头、页体、页尾等。
  3. 希望对你有帮助。

jsp是前端还是后端开发的

jsp是后端开发的。jsp的本质是一种servlet,而servlet又是服务器端的java应用程序,也就是按照道理来说jsp应该属于后端。 因为MVC分层中,jsp属于View层,现在jsp更多的作用变为了数据的展示和页面的显示,渐渐不用于逻辑的处理,所以综合起来虽然是后端的技术,但是应用上更贴近前端。 JSP技术有点类似ASP技术,它是在传统的网页HTML(标准通用标记语言的子集)文件(.htm,.html)中插入Java程序段(Scriptlet)和JSP标记(tag),从而形成JSP文件,后缀名为(*.jsp),用JSP开发的Web应用是跨平台的,既能在Linux下运行,也能在其他操作系统上运行。 以上内容参考 百度百科-JSP