SSM框架下,Jsp页面提交请求及action获取值得问题

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="上传" οnclick="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);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值