Web程序设计
实验报告
2013 年 12 月 27
2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>2.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="mycss.css">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<h1> This is my HTML page2. <br> </h1>
</body>
</html>
Mycss.css
@CHARSET "UTF-8";
h1{color: red;
background-color: gray;
text-align: left;
font-size: 58pt;}
body{color: blue;
background-image: url(Sunset.jpg);
}
源代码:
Index.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 'index.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form method="get" action="servlet/QueryServlet2">
<fieldset>
<legend align="center"> JDBC注册 </legend>
<center>
<p> 用户名: <input type="text" size="20" name="user" > </p>
<p> 密 码: <input type="text" size="20" name="password"> </p>
<p>
<input type="submit" value="注册" name="button2" >
</p>
</center>
</fieldset>
</form>
<form method="get" action="servlet/QueryServlet">
<fieldset>
<legend align="center"> JDBC登录 </legend>
<center>
<p> 用户名: <input type="text" size="20" name="user1" > </p>
<p> 密 码: <input type="text" size="20" name="password1"> </p>
<p>
<input type="submit" value="登录" name="button1">
</p>
</center>
</fieldset>
</form>
</body>
</html>
QueryServlet.java
package neuq.dzxx;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class QueryServlet extends HttpServlet {
/**
* Constructor of the object.
*/
private DataOperator DO;
public QueryServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String user1 = request.getParameter("user1");
String password1 = request.getParameter("password1");
String price="";
//String price = "no price";
try {
ResultSet rs = DO.query("select password from Info where name='"+user1+"';");
if(rs.next()){
price = rs.getString("password");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(price==password1) {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" password is correct ");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
}
}
QueryServlet2.java
package neuq.dzxx;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class QueryServlet2 extends HttpServlet {
/**
* Constructor of the object.
*/
private DataOperator DO2;
public QueryServlet2() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The DO2Get method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The DO2Post method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String user = request.getParameter("user");
String password = request.getParameter("password");
//String price = "no price";
try {
DO2.insert("insert into Info values('"+user+"','"+password+"')");
} catch (SQLException e) {
// TODO2 Auto-generated catch block
e.printStackTrace();
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DO2CTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" Login Successfully");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
DO2 = DataOperator.getInstance();
try {
String creatTableInfo = "create table Info (name int not null, " +
"password int not null " +
");";
DO2.creatTable(creatTableInfo);
DO2.insert("insert into Info values('1','10')");
} catch (SQLException e) {
// TODO2 Auto-generated catch block
e.printStackTrace();
}
}
}
江南大学教育学院课程设计报告课程名称Web技术与开发课题名称中国旅游论坛专业教育技术系班级教育技术06级02班学号**姓名**指导…
WEB程序设计实验报告院系名称:管理学院专业班级:电子商务0901班学生姓名:**学号:***20**年6月一、实验目的1、通过本…
课程设计报告学院系专业名称课程设计科目题目学号姓名指导教师完成时间计算机科学与技术系20xx计算机软件工程网络工程Web程序设计企…
Web程序设计实验报告Web程序设计实验报告院别专业班级学号姓名成绩计算机与通信工程学院计算机科学与技术20xx年12月271We…
洛阳理工学院课程设计报告课程名称Web程序设计课程设计设计题目学生成绩管理系统专业计算机科学与技术班级学号姓名完成日期20xx62…
PINGDINGSHANUNIVERSITY基于web的Java开发设计实训报告题目基于的系统的设计与实现院系软件学院专业年级姓名…
南昌工程学院基于WEB的程序开发专题实训报告题目网上花店系统的设计与实现课程名称基于WEB的程序开发系院信息工程学院专业信息管理与…
齐齐哈尔大学实习报告题目网上花店系统的设计与实现学院应用技术学院专业班级计应102班学生姓名张微微20xx年9月1目录一需求分析3…
洛阳理工学院课程设计报告课程名称设计题目专业班级学号王路霞姓名B10050802B100508计算机科学与技术图书销售管理系统AS…
Javaweb课程设计实训报告我们进行了为期一周的Javaweb的课程实训在这次实训中我觉得我学到了很多东西这次老师给我们安排了一…
Web程序设计课程设计目录1系统应用背景22系统需求分析33系统技术分析431技术分析4311ASPNET简介4312SQLSev…