<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<jsp:directive.page import="cn.com.csu.vo.BookInfo;" />
<html>
<head>
<title>查看书籍</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="images/css_w/table.css" rel="stylesheet" type="text/css">
<script>
function testChange(selectObj) {
var sobj = document.getElementById("s2");
len = sobj.children.length;
for(i = 0; i < len;i++) {
sobj.removeChild(sobj.children[0]);
}
if(selectObj.value == 1) {
var optionObj = document.createElement("option");
optionObj.setAttribute("value","11");
optionObj.innerHTML="历史";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","12");
optionObj.innerHTML="文化";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","13");
optionObj.innerHTML="法律";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","14");
optionObj.innerHTML="哲学/宗教";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","15");
optionObj.innerHTML="政治/军事";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","16");
optionObj.innerHTML="社会科学";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","17");
optionObj.innerHTML="自然科学";
sobj.appendChild(optionObj);
} else if (selectObj.value == 2) {
var optionObj = document.createElement("option");
optionObj.setAttribute("value","18");
optionObj.innerHTML="悬疑";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","19");
optionObj.innerHTML="武侠";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","20");
optionObj.innerHTML="言情";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","21");
optionObj.innerHTML="玄幻";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","22");
optionObj.innerHTML="恐怖";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","23");
optionObj.innerHTML="世界名著";
sobj.appendChild(optionObj);
} else if (selectObj.value == 3) {
var optionObj = document.createElement("option");
optionObj.setAttribute("value","24");
optionObj.innerHTML="金融投资";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","25");
optionObj.innerHTML="电子商务";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","26");
optionObj.innerHTML="商务史传";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","27");
optionObj.innerHTML="商务谈判";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","28");
optionObj.innerHTML="广告营销";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","29");
optionObj.innerHTML="企业管理";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","30");
optionObj.innerHTML="管理学理论";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","31");
optionObj.innerHTML="人力资源";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","32");
optionObj.innerHTML="会计";
sobj.appendChild(optionObj);
} else {
var optionObj = document.createElement("option");
optionObj.setAttribute("value","33");
optionObj.innerHTML="公务员";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","34");
optionObj.innerHTML="司法";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","35");
optionObj.innerHTML="外语考试";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","36");
optionObj.innerHTML="计算机";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","37");
optionObj.innerHTML="医药卫生";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","38");
optionObj.innerHTML="建筑工程";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","39");
optionObj.innerHTML="艺术体育";
sobj.appendChild(optionObj);
}
}
</script>
</head>
<BODY leftmargin="0" topmargin="0"><DIV><FORM action="addBookActionImpl.do?method=educationShow" method="post" name="myform" enctype="multipart/form-data">
<TABLE width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="left" scope="row">类别:<select name="bigSortId" id="s1" onchange="testChange(this)">
<option value="1">人文社科</option>
<option value="2">小说</option>
<option value="3">经济管理</option>
<option value="4">教育</option>
</select>
<select id="s2" name="smallSortId">
</select>
</tr>
<tr>
<td align="left" scope="row">市场价:
<input name="etPrice" type="text" id="shichangjia" size="15" maxlengtd="10" /></td>
<td>会员价:
<input name="currentPrice" type="text" id="huiyuanjia" size="15" maxlengtd="10" /></td>
</tr>
<tr>
<td align="left" scope="row">进货价:
<input name="bottomPrice" type="text" id="jinhuojia" size="15" maxlengtd="10" /></td>
<td>出版日期:
<input name="publishTime" type="text" id="chubanriqi" size="15" maxlengtd="10" /></td>
</tr>
<tr>
<td align="left" scope="row">出版社:
<input name="publisher" type="text" id="chubanshe" size="15" maxlengtd="10" /></td>
<td>作者:
<input name="author" type="text" id="zuozhe" size="15" maxlengtd="10" /></td>
</tr>
<tr>
<td align="left" scope="row">上架日期:
<input name="addTime" type="text" id="shangjiariqi" size="15" maxlengtd="10" /></td>
<td>书籍名称:
<input name="bookName" type="text" id="shujiming" size="15" maxlengtd="10" /></td>
</tr>
<tr>
<td align="left" scope="row">库存报警:
<input name="alarmNum" type="text" id="kucunbaojing" size="15" maxlengtd="10" /></td>
<td>进货数目:
<input name="storeNum" type="text" id="jinhuoshumu" size="15" maxlengtd="10" /></td>
</tr>
<tr>
<td colspan="3" align="left" scope="row">书籍图片:
<input type="file" name="bookImage"/></td>
</tr>
<tr>
<td height="111" colspan="3" valign="top" scope="row">书籍简介:
<textarea name="bookRe" cols="50" rows="8" id="shujijianjie"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center" scope="row"><input type="submit" name="Submit" value="提交" /> <input name="Submit2" type="reset" value="重置" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>这是我的JSP也面,就一个书籍图片是要选中图片的。
<jsp:directive.page import="cn.com.csu.vo.BookInfo;" />
<html>
<head>
<title>查看书籍</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="images/css_w/table.css" rel="stylesheet" type="text/css">
<script>
function testChange(selectObj) {
var sobj = document.getElementById("s2");
len = sobj.children.length;
for(i = 0; i < len;i++) {
sobj.removeChild(sobj.children[0]);
}
if(selectObj.value == 1) {
var optionObj = document.createElement("option");
optionObj.setAttribute("value","11");
optionObj.innerHTML="历史";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","12");
optionObj.innerHTML="文化";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","13");
optionObj.innerHTML="法律";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","14");
optionObj.innerHTML="哲学/宗教";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","15");
optionObj.innerHTML="政治/军事";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","16");
optionObj.innerHTML="社会科学";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","17");
optionObj.innerHTML="自然科学";
sobj.appendChild(optionObj);
} else if (selectObj.value == 2) {
var optionObj = document.createElement("option");
optionObj.setAttribute("value","18");
optionObj.innerHTML="悬疑";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","19");
optionObj.innerHTML="武侠";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","20");
optionObj.innerHTML="言情";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","21");
optionObj.innerHTML="玄幻";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","22");
optionObj.innerHTML="恐怖";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","23");
optionObj.innerHTML="世界名著";
sobj.appendChild(optionObj);
} else if (selectObj.value == 3) {
var optionObj = document.createElement("option");
optionObj.setAttribute("value","24");
optionObj.innerHTML="金融投资";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","25");
optionObj.innerHTML="电子商务";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","26");
optionObj.innerHTML="商务史传";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","27");
optionObj.innerHTML="商务谈判";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","28");
optionObj.innerHTML="广告营销";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","29");
optionObj.innerHTML="企业管理";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","30");
optionObj.innerHTML="管理学理论";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","31");
optionObj.innerHTML="人力资源";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","32");
optionObj.innerHTML="会计";
sobj.appendChild(optionObj);
} else {
var optionObj = document.createElement("option");
optionObj.setAttribute("value","33");
optionObj.innerHTML="公务员";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","34");
optionObj.innerHTML="司法";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","35");
optionObj.innerHTML="外语考试";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","36");
optionObj.innerHTML="计算机";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","37");
optionObj.innerHTML="医药卫生";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","38");
optionObj.innerHTML="建筑工程";
sobj.appendChild(optionObj);
optionObj = document.createElement("option");
optionObj.setAttribute("value","39");
optionObj.innerHTML="艺术体育";
sobj.appendChild(optionObj);
}
}
</script>
</head>
<BODY leftmargin="0" topmargin="0"><DIV><FORM action="addBookActionImpl.do?method=educationShow" method="post" name="myform" enctype="multipart/form-data">
<TABLE width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="left" scope="row">类别:<select name="bigSortId" id="s1" onchange="testChange(this)">
<option value="1">人文社科</option>
<option value="2">小说</option>
<option value="3">经济管理</option>
<option value="4">教育</option>
</select>
<select id="s2" name="smallSortId">
</select>
</tr>
<tr>
<td align="left" scope="row">市场价:
<input name="etPrice" type="text" id="shichangjia" size="15" maxlengtd="10" /></td>
<td>会员价:
<input name="currentPrice" type="text" id="huiyuanjia" size="15" maxlengtd="10" /></td>
</tr>
<tr>
<td align="left" scope="row">进货价:
<input name="bottomPrice" type="text" id="jinhuojia" size="15" maxlengtd="10" /></td>
<td>出版日期:
<input name="publishTime" type="text" id="chubanriqi" size="15" maxlengtd="10" /></td>
</tr>
<tr>
<td align="left" scope="row">出版社:
<input name="publisher" type="text" id="chubanshe" size="15" maxlengtd="10" /></td>
<td>作者:
<input name="author" type="text" id="zuozhe" size="15" maxlengtd="10" /></td>
</tr>
<tr>
<td align="left" scope="row">上架日期:
<input name="addTime" type="text" id="shangjiariqi" size="15" maxlengtd="10" /></td>
<td>书籍名称:
<input name="bookName" type="text" id="shujiming" size="15" maxlengtd="10" /></td>
</tr>
<tr>
<td align="left" scope="row">库存报警:
<input name="alarmNum" type="text" id="kucunbaojing" size="15" maxlengtd="10" /></td>
<td>进货数目:
<input name="storeNum" type="text" id="jinhuoshumu" size="15" maxlengtd="10" /></td>
</tr>
<tr>
<td colspan="3" align="left" scope="row">书籍图片:
<input type="file" name="bookImage"/></td>
</tr>
<tr>
<td height="111" colspan="3" valign="top" scope="row">书籍简介:
<textarea name="bookRe" cols="50" rows="8" id="shujijianjie"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center" scope="row"><input type="submit" name="Submit" value="提交" /> <input name="Submit2" type="reset" value="重置" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>这是我的JSP也面,就一个书籍图片是要选中图片的。
解决方案 »
- 页面有时会出现页面无法显示,刷新后又能正常显示了,这是为什么,请高手请教
- hibernate many to one 映射
- 一个服务器页面转到另一个服务器页面取得数据后返回给第一个服务器
- 鼠标在一个图片上移动有没有一个事件
- 问一个web的问题,比较烦人
- 数据库有外键约束,如何做批量插入
- SSH2整合,使用OpenSessionInViewFilter后,报no session!
- javamail如何获得邮件的大小?
- 菜鸟语句没看懂 求指导
- springMVC集成ajax实现异步验证
- Struts+Spring+ibatis insert的问题
- 有关jsp页面上jstl无法完全正常显示的问题 <c:if test="** eq **">
public static Map getParameters(HttpServletRequest request) {
//判断请求是否为multipart模式
boolean multipart = ServletFileUpload.isMultipartContent(request);
if(!multipart) return null;
String uploadPath = request.getSession().getServletContext().getRealPath("book_image");
DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
File file = new File(uploadPath);
if(!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
diskFileItemFactory.setRepository(file);
ServletFileUpload servletFileUpload = new ServletFileUpload();
servletFileUpload.setFileItemFactory(diskFileItemFactory);
servletFileUpload.setFileSizeMax(1000000 * 1024);
servletFileUpload.setHeaderEncoding("UTF-8");
try {
List paramItem = servletFileUpload.parseRequest(request); //将所有的请求信息 转为FileItem 封装模式
FileItem fileItem = null;
Map params = new HashMap();
FormFile formFile = null;
for(int i = 0, n = paramItem.size(); i < n; i++) {
fileItem = (FileItem)paramItem.get(i);
if (!fileItem.isFormField()) {
//不为表单元素类型时,该段内容为上传的文件内容
//System.out.println(fileItem.getFieldName()+":::"+fileItem.getName() + " --- " + fileItem.getContentType());
formFile = new FormFile();
String fileName = fileItem.getName();
formFile.setFileName(fileName.substring(fileName.lastIndexOf("\\") + 1));
formFile.setContentType(fileItem.getContentType());
formFile.setFileContent(fileItem.get());
params.put(fileItem.getFieldName(), formFile);
} else {
//普通表单元素
params.put(fileItem.getFieldName(), fileItem.getString());
}
}
return params;
} catch (FileUploadException e) {
e.printStackTrace();
return null;
}
}
public static void writeFileToDisk(FormFile formFile, String path) {
try {
OutputStream fileOutput = new FileOutputStream(path);
fileOutput.write(formFile.getFileContent());
fileOutput.flush();
fileOutput.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}[/code]
private BookDAO bookDAO = new BookDAOImpl();
public String educationShow(HttpServletRequest request,
HttpServletResponse response, VO vo, XMLConfig config) {
BookInfo bookInfo = (BookInfo)vo;
Map map = FileUploadProcessor.getParameters(request);
System.out.println(map+"-------");
FormFile formFile = (FormFile)map.get("bookImage");
String fileName = formFile.getFileName();
String path = "book_image/"+fileName;
path = request.getRealPath(path);
FileUploadProcessor.writeFileToDisk(formFile, path);
bookInfo.setBookImage(path);
System.out.println(path+"-------");
bookInfo.setBookName((String)map.get("bookName"));
bookInfo.setMarketPrice(Double.parseDouble(map.get("etPrice").toString()));
bookInfo.setCurrentPrice(Double.parseDouble(map.get("currentPrice").toString()));
bookInfo.setBottomPrice(Double.parseDouble(map.get("bottomPrice").toString()));
bookInfo.setAuthor((String)map.get("author"));
bookInfo.setPublisher((String)map.get("publisher"));
bookInfo.setBookRe((String)map.get("bookRe"));
bookInfo.setPublishTime((String)map.get("publishTime"));
bookInfo.setAddTime((String)map.get("addTime"));
bookInfo.setStoreNum(Integer.parseInt(map.get("storeNum").toString()));
bookInfo.setAlarmNum(Integer.parseInt(map.get("alarmNum").toString()));
bookInfo.setBookImage(path);
bookInfo.setViewNum(0);
bookInfo.setSmallSortId(Integer.parseInt(map.get("smallSortId").toString()));
bookInfo.setReNum(0); bookDAO.addInfo(bookInfo);
return "toHsearchPahe";
}
}这是我的Action 。我存入数据库后,我点击查看图书信息的时候中文出现乱码,而且图片也显示不了,给出的是一个绝对路径 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\EStore\book_image\12.jpg-------