SSM框架下,Jsp页面提交请求及action获取值得问题
2016-05-27 09:01
513 查看
JSP代码:
<form id="formid" action="poiAction!insertMsg.do" method="post">
<input type="file" id="filepath" name="filepath"/>
<!-- <input type="hidden" id="filename" name="text"/> -->
</form>
<input type="submit" value="上传" onclick="insert()"/>
<input type="button" value="下载">
<script type="text/javascript">
function insert(){
//获取选择文件的路径
//var txt=document.getElementById("filename");
//txt.value=document.getElementById("filepath").value;
//alert(txt.value);
//发送请求
if(document.getElementById("filepath")!=null){
document.forms[0].submit();
}
};
</script>
一开始我想的是利用document.getElementById().value来获取路径,alert之后发觉是能获取到的。这里先不考虑不同浏览器的问题。
后来之所以没这样是因为,如果你用的是struts2的话,你这样获取再在action用request.getParameter("filepath");就像是Servlet的用法,根本没体现到Struts2的特点。
所以,直接一个form表单控件把input file标签套住,用document.forms[0].submit();提交
Action类如何获取?
只需要声明filepath(与你input标签的name对应),写个get/set方法就可以直接获取
代码如下:
private String filepath;
public String getFilepath() {
return filepath;
}
public void setFilepath(String filepath) {
this.filepath = filepath;
}
//filepath=ServletActionContext.getRequest().getParameter("filename");
System.out.println(filepath);
<form id="formid" action="poiAction!insertMsg.do" method="post">
<input type="file" id="filepath" name="filepath"/>
<!-- <input type="hidden" id="filename" name="text"/> -->
</form>
<input type="submit" value="上传" onclick="insert()"/>
<input type="button" value="下载">
<script type="text/javascript">
function insert(){
//获取选择文件的路径
//var txt=document.getElementById("filename");
//txt.value=document.getElementById("filepath").value;
//alert(txt.value);
//发送请求
if(document.getElementById("filepath")!=null){
document.forms[0].submit();
}
};
</script>
一开始我想的是利用document.getElementById().value来获取路径,alert之后发觉是能获取到的。这里先不考虑不同浏览器的问题。
后来之所以没这样是因为,如果你用的是struts2的话,你这样获取再在action用request.getParameter("filepath");就像是Servlet的用法,根本没体现到Struts2的特点。
所以,直接一个form表单控件把input file标签套住,用document.forms[0].submit();提交
Action类如何获取?
只需要声明filepath(与你input标签的name对应),写个get/set方法就可以直接获取
代码如下:
private String filepath;
public String getFilepath() {
return filepath;
}
public void setFilepath(String filepath) {
this.filepath = filepath;
}
//filepath=ServletActionContext.getRequest().getParameter("filename");
System.out.println(filepath);
相关文章推荐
- js跨域问题浅析及解决方法优缺点对比
- 13个JavaScript图表(JS图表)图形绘制插件【转】
- 13个JavaScript图表(JS图表)图形绘制插件【转】
- 【DRP分销】--- JSP的四个常用对象的作用域
- javascript笔记:函数的定义与调用
- 用JS获取地址栏参数的方法
- java和javaScript区别简单理解
- [RxJS] Transformation operator: scan
- JSP系列:(4)JSP进阶-EL表达式和JSP标签
- Phaser.js音频资源处理篇
- Phaser.js事件系统及用户交互篇
- 理清JavaScript正则表达式--上篇
- Convention插件的使用(会涉及content目录,jsp必须放入这个下面才能映射成功基于注解的配置)
- javascript的变量声明和函数声明提升
- js通过location.search来获取页面传来的参数
- JS复制内容到剪切板
- ZeroClipboard.js复制内容到剪贴板(跨浏览器)
- JS 上传图片先预览
- Servlet/JSP-06 Session
- JSP系列:(3)JSP进阶-九大内置对象和四个域对象