function checkuname() { var name = $("#username").val(); if(name==""||(name.length<3||name.length>12)){ $("#checku").html("用户账号不能为空且长度在3~12位之间!"); $("input[id=username]").focus(); } else { $("#checku").html(""); $.ajax({ url : "checkUname.do", type : "post", data : "uname=" + name, dataType : "json", success:function(result){ if(result.info=="ng"){ $("#checku").html("用户名存在,请更换!"); $("input[id=username]").html(""); return false; }else{ $("#checku").html("可以用"); return true; } }, error:function(){ alert("请求失败!"); return false; } }); } } function checkpwd(){ var pwd=$("#txtPwd").val(); if(pwd==""||pwd.length<6||pwd.length>12){ $("#prompt_pwd").html("密码不能为空且长度在6~12位之间!"); $("input[id=txtPwd]").html(""); $("input[id=txtPwd]").focus(); return false; }else { $("#prompt_pwd").html("密码格式正确!"); return true;} } function checkpwdc(){ var pwd=$("#txtPwd").val(); var pwdc=$("#txtConfirmPwd").val(); if(pwdc==""||pwdc!=pwd){ $("#prompt_confirmpwd").html("两次密码要一致 !"); $("input[id=txtConfirmPwd]"); // $("input[name=passwordc]").focus(); return false; }else{ $("#prompt_confirmpwd").html("密码一致 !"); return true;} } function checktel(){ var tel=$("#txtPhone").val(); var regtel=/^(13|15|18|)\d{9}$/; if(tel==""||!regtel.test(tel)){ $("#prompt_phone").html("电话号码不能为空,且以13,15,17,18开头的11位"); $("input[id=txtPhone]").html(""); $("input[id=txtPhone]").focus(); return false; }else{ $("#prompt_phone").html("电话号码格式正确!"); return true; } } function checkname1(){ var uname=$("#txtName1").val(); if(uname==""||uname.length<2){ $("#prompt_name1").html("不能为空且长度在2位以上!"); $("input[id=txtName1]").html(""); $("input[id=txtName1]").focus(); return false; }else{ $("#prompt_name1").html("ok"); return true; }} function
时间: 2023-07-15 21:10:13 浏览: 149
Unfortunately, the code you provided is incomplete and ends abruptly without a proper function name or closing brackets. Please provide the complete code and specify what you need help with.
相关问题
<div class="wrapper"> <div class="content"> <h2>留言展示:</h2> </div> <!-- <h2>留言板</h2> --> <label for="user"><input type="text" id="user" placeholder="用户名" ></label> <label for="content"></label><input type="text" id="content" placeholder="留言内容" > <button id="btn"> 提交</button> </div> <!-- 首先获取数据库的内容 --> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script> <script src="../../JavaScript/jquery.js"></script> <!-- <script src="../cunminjs/liuyanban.js"></script>--> <script> $("#btn").click(function(){ var username = $("#user").val(); var content = $("#content").val(); // console.log("=="); $.ajax({ url:'../liuyanban.php', data:{query:'add',cm_name:username,cm_content:content}, dataType:'json', method:'post', success(res){ console.log(res); if(res.code == 200){ alert("数据添加成功!"); $('.content').html(''); $("#user").val(""); $("#content").val(""); getInfo(); } } }) }); </script> <script> getInfo(); function getInfo(){ $.ajax({ url:'../liuyanban.php', data:{query:'select'}, dataType:'json', method:'post', success(res){ // console.log(res); if(res){ var str = ""; for(var i=0;i<res.length;i++){ str += `<span class="user">${res[i].username}</span>:<span>${res[i].content}</span>  <span>${res[i].time}</span> <br>` } $(".content").append(str); } } }) } </script>
以上代码是一个留言板的前端页面。其中含有一个用户名输入框、一个留言输入框和一个提交按钮。用户在输入用户名和留言内容后,点击“提交”按钮即可将留言提交到后端数据库中。前端使用了jQuery库,并引用了一个不确定来源的JavaScript文件。
<h1>上传/下载文件</h1> <form method="post" action="/file/upload" enctype="multipart/form-data"> <input type="file" name="file" id="fileInput"/> <input type="submit" value="上传" /> </form> <hr> <form method="post" action="/file/download" > <input type="text" name="fileName" placeholder="请输入文件名" /> <input type="submit" value="下载" id="downloadBtn" /> </form> public class SFTPUtil { private static final String host = "10.60.0.160"; private static final int port = 22; private static final String username = "root"; private static final String password = "Z20"; private static Session session = null; public static void connect() throws Exception { } public static void upload(MultipartFile file, String path, String fileName) throws Exception { } public static boolean download(HttpServletResponse response, String path, String fileName) throws Exception { } @Controller @RequestMapping("/file") public class FileController { private static final String UPLOAD_PATH = "/data/sftp/adtuser1/upload/winbidding/"; private static final String DOWNLOAD_PATH = "/data/sftp/adtuser1/upload/winbidding/"; @PostMapping("/upload") @ResponseBody public ModelAndView upload(@RequestParam("file") MultipartFile file) { } @PostMapping("/download") public ModelAndView download(@RequestParam("fileName") String fileName, HttpServletResponse response) throws Exception { } 数据库有host port username password UPLOAD_PATH DOWNLOAD_PATH csmc字段,把上边写死的改成数据库查询,前台页面增加csmc字段下拉框,根据csmc字段把查出来的配置数据完成上传下载功能,用的mysql数据库,把代码改好写出来
首先需要在数据库中创建一个表,用于存储SFTP连接的相关信息:
```sql
CREATE TABLE sftp_config (
id INT PRIMARY KEY AUTO_INCREMENT,
csmc VARCHAR(50),
host VARCHAR(50),
port INT,
username VARCHAR(50),
password VARCHAR(50),
upload_path VARCHAR(255),
download_path VARCHAR(255)
);
```
然后在Spring Boot项目中创建一个SFTPUtil类,用于实现SFTP上传和下载功能:
```java
import com.jcraft.jsch.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.util.Properties;
public class SFTPUtil {
private String host;
private int port;
private String username;
private String password;
private String uploadPath;
private String downloadPath;
private Session session;
public SFTPUtil(String host, int port, String username, String password, String uploadPath, String downloadPath) {
this.host = host;
this.port = port;
this.username = username;
this.password = password;
this.uploadPath = uploadPath;
this.downloadPath = downloadPath;
}
public void connect() throws Exception {
JSch jsch = new JSch();
session = jsch.getSession(username, host, port);
session.setPassword(password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
}
public void upload(MultipartFile file, String fileName) throws Exception {
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
channel.cd(uploadPath);
InputStream inputStream = file.getInputStream();
channel.put(inputStream, fileName);
inputStream.close();
channel.disconnect();
}
public boolean download(HttpServletResponse response, String fileName) throws Exception {
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
channel.cd(downloadPath);
SftpATTRS attrs = channel.lstat(fileName);
if (attrs == null) {
channel.disconnect();
return false;
}
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
OutputStream outputStream = response.getOutputStream();
channel.get(fileName, outputStream);
outputStream.flush();
outputStream.close();
channel.disconnect();
return true;
}
}
```
然后在Spring Boot项目中创建一个FileController类,用于处理文件上传和下载请求:
```java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("/file")
public class FileController {
@Autowired
private JdbcTemplate jdbcTemplate;
@PostMapping("/upload")
@ResponseBody
public String upload(@RequestParam("file") MultipartFile file, @RequestParam("csmc") String csmc) {
try {
// 从数据库中获取SFTP连接配置信息
String sql = "SELECT * FROM sftp_config WHERE csmc = ?";
Map<String, Object> map = jdbcTemplate.queryForMap(sql, csmc);
String host = (String) map.get("host");
int port = (int) map.get("port");
String username = (String) map.get("username");
String password = (String) map.get("password");
String uploadPath = (String) map.get("upload_path");
String fileName = file.getOriginalFilename();
// 使用SFTP上传文件
SFTPUtil sftpUtil = new SFTPUtil(host, port, username, password, uploadPath, null);
sftpUtil.connect();
sftpUtil.upload(file, fileName);
return "上传成功";
} catch (Exception e) {
e.printStackTrace();
return "上传失败";
}
}
@PostMapping("/download")
public void download(@RequestParam("fileName") String fileName, @RequestParam("csmc") String csmc, HttpServletResponse response) throws Exception {
// 从数据库中获取SFTP连接配置信息
String sql = "SELECT * FROM sftp_config WHERE csmc = ?";
Map<String, Object> map = jdbcTemplate.queryForMap(sql, csmc);
String host = (String) map.get("host");
int port = (int) map.get("port");
String username = (String) map.get("username");
String password = (String) map.get("password");
String downloadPath = (String) map.get("download_path");
// 使用SFTP下载文件
SFTPUtil sftpUtil = new SFTPUtil(host, port, username, password, null, downloadPath);
sftpUtil.connect();
boolean result = sftpUtil.download(response, fileName);
if (!result) {
response.getWriter().write("文件不存在");
}
}
@GetMapping("/csmcList")
@ResponseBody
public List<String> getCsmcList() {
// 从数据库中获取所有的csmc字段
String sql = "SELECT DISTINCT csmc FROM sftp_config";
List<String> csmcList = jdbcTemplate.queryForList(sql, String.class);
return csmcList;
}
}
```
最后,在HTML页面中加入下面的代码,即可实现文件上传和下载:
```html
<h1>上传/下载文件</h1>
<form method="post" action="/file/upload" enctype="multipart/form-data">
<input type="file" name="file" id="fileInput"/>
<select name="csmc" id="csmcSelect"></select>
<input type="submit" value="上传"/>
</form>
<hr>
<form method="post" action="/file/download">
<input type="text" name="fileName" placeholder="请输入文件名"/>
<select name="csmc" id="csmcSelect"></select>
<input type="submit" value="下载" id="downloadBtn"/>
</form>
<script>
// 获取csmc列表
$.get("/file/csmcList", function (data) {
var csmcSelect = $("#csmcSelect");
for (var i = 0; i < data.length; i++) {
var option = $("<option>").val(data[i]).text(data[i]);
csmcSelect.append(option);
}
});
</script>
```
阅读全文