JSP实验报告文档格式.docx

上传人:b****3 文档编号:7280874 上传时间:2023-05-08 格式:DOCX 页数:21 大小:32.37KB
下载 相关 举报
JSP实验报告文档格式.docx_第1页
第1页 / 共21页
JSP实验报告文档格式.docx_第2页
第2页 / 共21页
JSP实验报告文档格式.docx_第3页
第3页 / 共21页
JSP实验报告文档格式.docx_第4页
第4页 / 共21页
JSP实验报告文档格式.docx_第5页
第5页 / 共21页
JSP实验报告文档格式.docx_第6页
第6页 / 共21页
JSP实验报告文档格式.docx_第7页
第7页 / 共21页
JSP实验报告文档格式.docx_第8页
第8页 / 共21页
JSP实验报告文档格式.docx_第9页
第9页 / 共21页
JSP实验报告文档格式.docx_第10页
第10页 / 共21页
JSP实验报告文档格式.docx_第11页
第11页 / 共21页
JSP实验报告文档格式.docx_第12页
第12页 / 共21页
JSP实验报告文档格式.docx_第13页
第13页 / 共21页
JSP实验报告文档格式.docx_第14页
第14页 / 共21页
JSP实验报告文档格式.docx_第15页
第15页 / 共21页
JSP实验报告文档格式.docx_第16页
第16页 / 共21页
JSP实验报告文档格式.docx_第17页
第17页 / 共21页
JSP实验报告文档格式.docx_第18页
第18页 / 共21页
JSP实验报告文档格式.docx_第19页
第19页 / 共21页
JSP实验报告文档格式.docx_第20页
第20页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

JSP实验报告文档格式.docx

《JSP实验报告文档格式.docx》由会员分享,可在线阅读,更多相关《JSP实验报告文档格式.docx(21页珍藏版)》请在冰点文库上搜索。

JSP实验报告文档格式.docx

}publicStringgetAge(){

returnage;

}publicvoidsetAge(Stringage){

this.age=age;

}publicStringgetBorn(){

returnborn;

}publicvoidsetBorn(Stringborn){

this.born=born;

}publicStringgetAddress(){

returnaddress;

}publicvoidsetAddress(Stringaddress){

this.address=address;

}publicStringgetIntroduce(){

returnintroduce;

}publicvoidsetIntroduce(Stringintroduce){

this.introduce=introduce;

}

}

(2)用户注册页面的代码如下:

<

%@pagecontentType="

text/html;

charset=gb2312"

language="

java"

import="

java.sql.*"

errorPage="

%>

html>

head>

metahttp-equiv="

Content-Type"

content="

/>

linkhref="

CSS/style.css"

type="

text/css"

rel="

stylesheet"

>

title>

用户注册<

/title>

/head>

scripttype="

text/javascript"

functionuserCheck(){

if(document.form1.username.value=="

){

window.alert("

请输入用户名"

);

returnfalse;

if(document.form1.password.value=="

请输入用户密码"

if(document.form1.repassword.value=="

请输入密码确认"

if(document.form1.repassword.value!

=document.form1.password.value){

您输入的两次密码并不相同"

if(document.form1.realname.value=="

请输入用户真实姓名!

if(document.form1.age.value=="

请输入用户年龄!

if(document.form1.born.value=="

请输入出生日期"

if(document.form1.address.value=="

请输入地址"

if(document.form1.introduce.value=="

请输入自我介绍"

returntrue;

}<

/script>

body>

formaction="

showUserInfo.jsp"

method="

post"

name="

form1"

onSubmit="

returnuserCheck()"

tablewidth="

409"

border="

1"

<

tr>

td>

用户名:

/td>

inputtype="

text"

username"

/tr>

密码:

password"

确认:

repassword"

用户真实姓名:

realname"

性别:

radio"

sex"

value="

男"

checked="

checked"

&

nbsp;

男&

女"

年龄:

age"

出生:

born"

地址:

address"

介绍:

textareaname="

introduce"

rows="

5"

id="

/textarea>

/table>

submit"

Submit"

注册"

input

reset"

Submit2"

重置"

/form>

/body>

/html>

(3)显示用户注册信息的页面代码如下:

显示用户注册信息<

%request.setCharacterEncoding("

gb2312"

jsp:

useBeanid="

userInfo"

scope="

request"

class="

com.UserInfo"

/>

setPropertyname="

property="

*"

%=userInfo.getUsername()%>

%=userInfo.getPassword()%>

%=userInfo.getRepassword()%>

%=userInfo.getRealname()%>

%=userInfo.getSex()%>

%=userInfo.getAge()%>

%=userInfo.getBorn()%>

%=userInfo.getAddress()%>

%=userInfo.getIntroduce()%>

1

(1)在web.xml配置文件获取编写以下代码:

?

xmlversion="

1.0"

encoding="

UTF-8"

web-appversion="

2.5"

xmlns="

xmlns:

xsi="

http:

//www.w3.org/2001/XMLSchema-instance"

xsi:

schemaLocation="

servlet>

servlet-name>

text<

/servlet-name>

jsp-file>

/index.jsp<

/jsp-file>

init-param>

param-name>

username<

/param-name>

param-value>

城中狼<

/param-value>

/init-param>

sex<

男<

address<

长春市和平大街5号<

email<

****************<

/servlet>

servlet-mapping>

url-pattern>

/url-pattern>

/servlet-mapping>

/web-app>

(2)创建index.jsp页面,该页面通过config对象获取web.xml配置信息,主要代码如下:

%out.println("

+config.getInitParameter("

))

out.print("

br>

out.println("

));

家庭住址:

email:

email"

2

(1)创建名称index.jsp,该页面的代码如下:

charset=gb2312"

import="

error.jsp"

%>

%inta=10,b=0;

输出结果:

+a/b);

(2)创建名称error.jsp,该页面的代码如下:

isErrorPage="

true"

获取发生错误如下:

%=exception.getMessage()%>

JDBC的代码如下:

importjava.sql.*;

publicclassJDBConnection{privatefinalStringdbDrive="

com.mysql.jdbc.Driver"

privatefinalString

url="

jdbc:

mysql:

//localhost:

3306/db_text?

characterEncoding=gb2312"

privatefinalStringuserName="

sa"

privatefinalStringpassword="

privateConnectioncon=null;

publicJDBConnection()

{//通过构造方法加载数据库驱动try{Class.forName(dbDrive).newInstance();

}

catch(Exceptionex){System.out.println("

数据库加载失败"

}}

publicbooleancreatConnection()

{//创建数据库连接try{con=DriverManager.getConnection(url,userName,password);

con.setAutoCommit(true);

catch(SQLExceptione){}returntrue;

publicbooleanexecuteUpdate(Stringsql)

{//对数据表的增加、修改和删除的操作if(con==null){creatConnection();

try{Statementstmt=con.createStatement();

intiCount=stmt.executeUpdate(sql);

System.out.println("

操作成功,所影响的记录数为"

+String.valueOf(iCount));

catch(SQLExceptione)

{returnfalse;

}}

publicResultSetexecuteQuery(Stringsql)

{//对数据库的查询操作ResultSetrs;

try{if(con==null){creatConnection();

Statementstmt=con.createStatement();

rs=stmt.executeQuery(sql);

returnnull;

catch(Exceptione)

{returnnull;

returnrs;

}}

publicvoidcloseConnection()

{//关闭数据库连接if(con==null){try{con.close();

}catch(SQLExceptione){}}}}

1

(1)创建名为CommonUpload.jsp的页面文件,该页面中完成三个文件的上传代码如下:

%@pagelanguage="

pageEncoding="

utf-8"

多文件上传<

<

CommonUpload.do"

enctype="

multipart/form-data"

上传文件:

第一个文件:

file"

Upload"

第二个文件:

第三个文件:

<

上传"

(2)web.xml文件中配置CommonUpload.do请求,代码如下:

2.4"

xsi:

CommonUpload<

servlet-class>

sunyang.CommonUpload<

/servlet-class>

/CommonUpload.do<

welcome-file-list>

welcome-file>

CommonUpload.jsp<

/welcome-file>

/welcome-file-list>

(3)定义Servlet类,处理上传请求,并对上传文件类型进行限制,限制为jpg格式,代码如下:

packagesunyang;

publicclassCommonUploadextendsHttpServlet{

protectedvoiddoGet(HttpServletRequestrequest,

HttpServletResponseresponse)throwsServletException,IOException{

doPost(request,response);

protectedvoiddoPost(HttpServletRequestrequest,

DiskFileItemFactoryfactory=newDiskFileItemFactory();

factory.setRepository(newFile(request.getRealPath("

/"

)));

factory.setSizeThreshold(1024*1024*20);

ServletFileUploadupload=newServletFileUpload(factory);

Listitems=null;

try{

items=upload.parseRequest(request);

}catch(FileUploadExceptione

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2