文档库 最新最全的文档下载
当前位置:文档库 › web程序设计报告

web程序设计报告

web程序设计报告
web程序设计报告

Web程序设计

实验报告

院别计算机与通信工程学院专业计算机科学与技术

班级学号

姓名

成绩

2013 年12 月27

【实验编号】 1

【实验名称】熟悉环境和css的使用

【实验内容】

完成三个html页面,三个页面之间可以通过链接互相访问,自由的设置其中的控件,使用一个css表单来美化这三个页面。

【实验步骤】

index.html

index.html

Sunset

link 1

link 2

1.html

1.html

This is my HTML page1.

2.html

2.html

This is my HTML page2.

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);

}

【实验编号】 2

【实验名称】熟悉DOM的原理和使用

【实验内容】

在刚才建立的index.html页面添加一个删除按钮,做一个基于DOM的js函数,每次点击删除按钮就会将刚才生成的一个控件删除。

【实验步骤】

代码:

index.html


截图:

【实验编号】 3

【实验名称】学习使用servlet

【实验内容】将一个字符串使用doGet方法提交给Servlet,Servlet统计其中每个字母出现的次数,然后打印在页面上【实验步骤】

代码:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath =

request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

My JSP 'index.jsp' starting page

This is my JSP page.

学号:

姓名:

字符串:

【实验编号】4

【实验名称】使用servlet和JDBC访问数据库

【实验内容】

制作一个页面,通过向数据库中添加、查找来实现用户注册,登录功能。【实验步骤】

源代码:

Index.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%

String path = request.getContextPath();

String basePath =

request.getScheme()+"://"+request.getServerName()+":"+request.getServ erPort()+path+"/";

%>

My JSP 'index.jsp' starting page

JDBC注册

用户名:

密   码: 

JDBC登录

用户名:

密   码: 

   

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.

*/

public void destroy() {

super.destroy(); // Just puts "destroy" string in log

// Put your code here

}

/**

* The doGet method of the servlet.

*

* 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.

*

* 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("");

out.println("");

out.println(" A Servlet");

out.println(" ");

out.print(" password is correct ");

out.println(" ");

out.println("");

out.flush();

out.close();

}

}

/**

* Initialization of the servlet.

*

* @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.

*/

public void destroy() {

super.destroy(); // Just puts "destroy" string in log

// Put your code here

}

/**

* The DO2Get method of the servlet.

*

* 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.

*

* 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("");

out.println("");

out.println(" A Servlet");

out.println(" ");

out.print(" Login Successfully");

out.println(" ");

out.println("");

out.flush();

out.close();

}

/**

* Initialization of the servlet.

*

* @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程序设计实验报告

Web程序设计实验报告 姓名:冯刚 学号:200905030324 班级:计科3班

Html代码: 1.首页代码 无标题文档