HTML from 表单提交请求到servlet 实例解析

不点 阅读:231 2021-03-31 23:24:13 评论:0

HTML源码展示:

<!DOCTYPE html> 
<html> 
<head> 
<style type="text/css"> 
div#container{width:100%;} 
 
div#menu {background-color:#e2e6ee;height:500px;width:50%;float:left;text-align:center; background-image:margin:0; color:#333333;} 
div#content {background-color:#EEEEEE;height:500px;width:50%;float:left;width:expression(window.screen.height);} 
body{background:#1d3647;} 
#from{ margin-top:20%;margin-left:10%;} 
#logo{margin-top:20%; float:right; margin-right:10%; } 
#adv{margin-top:27%; float:right; margin-right:1%; font:"宋体"; color:#777; font-size:14px;} 
</style> 
</head> 
 
<body> 
<br/> 
<br/> 
 
 
<div id="container"> 
 
 
 
<div id="menu"> 
<img src="platefrom/images/LOGO01.gif"id="logo"/><br/> 
<div id="adv"> 
<strong>  1- 地区商家信息网门户站建立的首选方案...</strong><br/><br/> 
<strong>2- 一站通式的整合方式,方便用户使用...</strong><br/><br/> 
<strong>3- 强大的后台系统,管理内容易如反掌...</strong> 
</div> 
 
</div> 
 
<div id="content"> 
<!--表单--> 
 <form action="./LoginServlet" method="get" id="from"> 
 <strong style="font:'宋体'; color:#777; font-size:16px;">登入后台信息管理</strong><br/><br/> 
用户名:        <input type="text" name="username"  /><br /><br/> 
密  码:        <input type="password" name="password" /><br /> <br/><br/>    
 
<input type="submit"  value="登    陆" style="font:'宋体'; font-size:16px;"/>       
<input type="submit"  value="取    消" style="font:'宋体'; font-size:16px;"/> 
</form> 
</div> 
 
 
</div> 
 
</body> 
</html>
 
后台Servlet
package com.platefrom.servlet; 
 
import java.io.IOException; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
public class LoginServlet extends HttpServlet { 
 
	/** 
	 *  
	 */ 
	private static final long serialVersionUID = 1L; 
 
	@Override 
	public void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException { 
		// TODO Auto-generated method stub 
		//默认用户名和密码:admin和123456 
		String username=request.getParameter("username"); 
		String password=request.getParameter("password"); 
		//逻辑判断操作 
		if(username.equals("admin")&&password.equals("123456")){ 
			//功能界面 
			response.sendRedirect("./platefrom/main.html"); 
		}else{ 
			//登入页面 
			response.sendRedirect("./platefrom/login.html"); 
		} 
		 
	} 
 
	@Override 
	public void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException { 
		// TODO Auto-generated method stub 
		this.doGet(request, response); 
	} 
	 
	 
 
} 

 

声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
排行榜
KIKK导航

KIKK导航

关注我们