我的action为什么会执行两边呢。。。

yyyyy_111 2014-02-12 05:17:08
这是action
public String createSearch(){
String taskname = sRequest.getParameter("taskname");
String sql = sRequest.getParameter("sql");
//创建时间戳
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String requestfile = dateFormat.format( now );
String requestname = dateFormat.format( now );
//创建目录
String filePath=ServletActionContext.getServletContext().getRealPath("/search/"+requestfile);
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.mkdir();
//生成txt文档
PrintWriter out=null;
try {
out = new PrintWriter(new BufferedWriter(new FileWriter(filePath+"\\"+"Searcher_"+requestname+".txt")));
out.println(sql);
} catch (IOException e) {
request.put("errmsg", StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage());
e.printStackTrace();
return ERROR;
}finally{
out.close();
}
String taskdir = filePath;
//将获得的数据插入数据库
SearchModel search = new SearchModel();
search.setTaskname(taskname);
search.setRequestfile(requestfile);
search.setTaskdir(taskdir);
try {
searchService.addSearch(search);
} catch (Exception e) {
request.put("errmsg", "很抱歉,系统异常,请重试!");
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}

这是jsp
</style>

<script language="javascript" type="text/javascript">
function createfile(){
var taskname=document.getElementById("taskname").value;
if(taskname==null || taskname==""){
alert("请输入任务名称!");
document.getElementById("taskname").focus();
return false;
}
var sql=document.getElementById("sql").value;
if(sql==null || sql==""){
alert("请输输入查询条件!");
document.getElementById("sql").focus();
return false;
}
document.forms[0].action='remoteSearch.action';
document.forms[0].submit();
}
function go(){
var selObj=document.getElementById('page');
var value=selObj.options[selObj.selectedIndex].value;

document.getElementById('pageNo').value=value;
document.forms[0].action='remoteList.action';
document.forms[0].submit();

}
function check(id){
//alert(id);
document.getElementById('id').value=id;
document.forms[0].action='check.action';
//alert(document.forms[0].action);
document.forms[0].submit();
}


</script>
</head>
<body>
<div id="main">
</div>
<form id="remote" method="post">
<s:hidden id="pageNo" name="pageNo" ></s:hidden>
<s:hidden id="id" name="id" ></s:hidden>
<div class="contbj">
<div class="table">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" align="right">任务名称:</td>
<td ><input type="text" name="taskname" id="taskname" style="width:100px;" class="tbox"/></td>
</tr>
<tr>
<td align="right">查询条件:</td>
<td ><textarea name="sql" id="sql" style="width:300px; height=600px;" ></textarea></td>
<td ><input type="button" onclick="javascript:createfile();" name="button" id="button" value="创建" class="btn" /></td>
</tr>

配置文件
<action name="remoteSearch" class="searchAction" method="createSearch">
<result name="success">/WEB-INF/jsp/page/remotesearch.jsp</result>
<result name="error">/WEB-INF/jsp/error.jsp</result>
</action>

帮忙看看呐。。。。
...全文
66 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

5,655

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧