Form表单图片提交
javaWeb上传图片都需要哪些东西
1.添加Form表单必须要加关键词
** enctype=“multipart/form-data” **
提交方式必须为 post 方式
<form action="${pageContext.request.contextPath}/addPhones.do" method="post" enctype="multipart/form-data">
手机名称:<input type="text" name="phName" required="required" /> <br/>
手机价格:<input type="text" name="phPrice" id="bookPrice" required="required" /> <br/>
手机库存:<input type="text" name="phNum" required="required" /> <br/>
手机图片:<input type="file" name="phImage" required="required"/> <br/>
手机简介(非必填):
<textarea name="phInfo" style="width: 300px;height: 200px;resize:none; vertical-align: top;" ></textarea> <br/>
<input type="submit" value="添加"/>
</form>
2.写两个监听器,存储磁盘的路径,和http协议路径,拼接字符串
2.1 获取站点名称 String 中的subString方法截取字符串
磁盘的路径:
public void contextInitialized(ServletContextEvent see) {
ServletContext app = see.getServletContext