日期:2014-05-17  浏览次数:20801 次

如何获取上传文件的文件名
本帖最后由 lotnleave 于 2013-04-14 01:03:21 编辑
我现在做了一个表单发邮件,可以插附件 可是不知道怎么获取真实的文件名

求解 谢谢 



<%@ 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>Test页面</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">
</head>
<body>
<form action="toMail.action" method="post" encType="multipart/form-data" >
<table cellspacing="2" cellpadding="2" align="center" border="0">
<tr>
<td style="width:15%">接&nbsp;收&nbsp;人:</td>
<td><input name="mailReciver" type="text" id="mailReciver" style="width:80%" maxlength=255 /></td>
</tr>
<tr>
<td style="width:15%">发&nbsp;送&nbsp;人:</td>
<td><input name="mailSender" type="text" id="mailSender" style="width:80%" maxlength=255 /></td>
</tr>
<tr>
<td style="width:15%">主&nbsp;&nbsp;&nbsp;&nbsp;题:</td>
<td><input name="mailSubject" type="text" id="title" style="width:80%" maxlength=255 /></td>
</tr>
<tr>
<td width="15%"><input type="text" name="mailContent" style="width:80%" maxlength=255 /></td>
<td><input type="file" name="attachFileNames" /></td>
</tr>
<tr>
<td align="center" width="60%"><input type="submit" value="发送" class="button" /></td>
</tr>
</table>
</form>
</body>
</html>



//发送附件
for (String fileName : smail.getAttachFileNames()) {  
mailMessage.addAttachment(MimeUtility.encodeWord(fileName), new File(fileName));  
            }  



请问如何在Java代码中获取真实文件名??



------解决方案--------------------
引用:
引用:引用:引用:引用:引用:<td><span style="color: #FF0000;"><input type="file" name="attachFileNames" />……

不可以吧,因为你的表单是提交给struts框架的,通过它的总控,然后再交给分派action,就是我们平时经常用的那种action。而Impl那种类属于逻辑业务层了,不属于struts框架管辖范围了。但你可以在action里面调用Impl的函数啊,把表单获取的数据作为参数传进Impl函数里。