❶ java web网页登录功能原理(最好有代码❳
想要实现一个简单的登录功能的话,可以使用Servlet+jsp来实现,jsp编写登录界面和登录后的要出现信息界面和登录失败的信息界面,Servlet类用来对表单提交的用户名和密码进行判断和处理。
具体代码如下:
Servlet类:
public class DemoServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String loginname = request.getParameter("loginname");
String password = request.getParameter("password");
if(loginname.equals("a") && password.equals("a")){
request.setAttribute("msg", "登录成功");
request.getRequestDispatcher("/loginsuccess.jsp").forward(request, response);
}else{
request.setAttribute("msg", "登录失败");
request.getRequestDispatcher("/loginsuccess.jsp").forward(request, response);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Demo</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">
</head>
<body>
<form action="demoServlet" method="post">
<input type="text" name="loginname"/><br/>
<input type="password" name="password"/><br/>
<input type="submit" value="登录"/>
</form>
</body>
</html>
登录信息页面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="标签库地址"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'loginsuccess.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">
</head>
<body>
${msg }
</body>
</html>
需要介绍一下:登录信息的这个页面中的${msg }是使用jstl标签,需要在jsp页面中导入jstl标签库,使用这个标签库可以节省很多代码量。
❷ 大神,跪求java web 一个用户用户注册登录,不用连接数据库,不要连接数据库!!
这个简单,定义一个static Map<String,User>,每注册一个就往Map中put一条数据,以登录名为key,以用户User类为value。
登录的时候拿着登录名去找Map,如果有匹配到就对比密码是否正确,密码输入正确就表示可以登录成功,密码匹配错误就提示密码错误;
如果拿着登录名找Map没有找到信息,说明此登录名没有注册,就是提示注册。
❸ 用java web编写一个用户注册界面(只要写出以下要求就行)
一步步更新:页面
<form action="regist.servlet" method="post"><table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="tableAdd borTop"> <tr> <th width="14%" height="30" nowrap>用户名</th> <td class="pl5"> <INPUT id="sName" name="name" type="text" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>密码</th> <td class="pl5"> <INPUT name="password" type="password" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>确认密码</th> <td class="pl5"> <INPUT name="confrimPwd" type="password" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>性别</th> <td class="pl5"> 男<INPUT name="sex" type="radio" value="1" checked="checked" size="20"> 女<INPUT name="sex" type="radio" value="0" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>爱好</th> <td class="pl5"> <INPUT name="enjoy" type="checkbox" size="20" value="篮球">篮球 <INPUT name="enjoy" type="checkbox" size="20" value="足球">足球 </td> </tr> <tr> <th width="14%" height="30" nowrap>生日</th> <td class="pl5"> <INPUT name="brithday" type="text" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>备注</th> <td class="pl5"> <textarea rows="5" cols="200" name="remark"></textarea> </td> </tr> <tr> <th width="14%" height="30" nowrap> </th> <td class="pl5"> <input type="submit" value="提交"> <input type="reset" value="重置"> </td> </tr></table></form>
数据库部分:
import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import com.mysql.jdbc.Connection;import com.mysql.jdbc.Statement;public class DataBaseUtil { public static Connection getConnection() throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://192.168.100.113/datebase", "username", "password"); return conn; } public static Statement getPS() throws ClassNotFoundException, SQLException { Statement statement = (Statement) getConnection().createStatement(); return statement; } public static void close(Connection conn,Statement st,ResultSet rs) throws SQLException{ if(rs != null) { rs.close(); } if(st != null) { st.close(); } if(conn != null) { conn.close(); } }}
❹ 关于javaWeb单点登录
你这样入手,给你列出整个简单流程,你自己思考一下:
1)下载,配置 Tomcat。
2)写 JSP 与 Servlet ,调用 MySQL 或其他数据库。
3)在 Tomcat 部署你的应用程序。
4)在浏览器运行你的应用程序。
一个简单的测试系统,主要由两个页面组成就够了:
1)登录页面。
2)登录成功后,显示的主页面。
后台程序,只要写一个就行了:
1)接收登录的用户名密码,去查询数据库。
❺ 用java写一个手机商城注册界面代码
这篇文章主要介绍了java通过JFrame做一个登录系统的界面完整代码示例,具有一定借鉴价值,需要的朋友可以参考下。
在java的JFrame内通过创建匿名对象的方式做登录界面
package com.sxt;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginFrame extends JFrame{
JTextField txtname=new JTextField();
JPasswordField txtpass=new JPasswordField();
JButton bl=new JButton("登录");
JButton bg=new JButton("关闭");
//构造无参构造器把主要的方法放在构造器里,然后在main方法里面调
public LoginFrame(){
setBounds(25,25,250,250);
Container c = getContentPane();
c.setLayout(new GridLayout(4,2,10,10));
c.add(new JLabel("用户名"));
c.add(txtname);
c.add(new JLabel("密码"));
c.add(txtpass);
c.add(bl);
c.add(bg);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
//注意:此处是匿名内部类
bg.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
}
);
//注意:此处是匿名内部类
bl.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
❻ 急急急!!!!在线等!!javaweb怎么判断管理员和普通用户登录,求代码!!!
if(request.getParameter("userclass").equals("用户"))
...
else if(request.getParameter("userclass").equals("管理员")
...
else
...
❼ java web 的一个登录注册案例,控制台出现At least one JAR was scanned for TLDs yet contained no TLDs
user是一个对象,重写一下user的tostring方法
❽ javaweb的学生注册登录(学号,姓名,密码),删除,修改
如果不多的话就直接修改 要更新就 update table set id='19'+substring(id,1,4)+'00'+substring(id,5,3)