5,655
社区成员
发帖
与我相关
我的任务
分享
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;
}
</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>