编辑简而言之,我的jsp是这样的:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script src="../js/jquery/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery/jquery-ui.min.js"></script>
<script src="../js/jquery/jquery.validate.min.js" type="text/javascript"></script>
<script src="../js/myJs.js" type="text/javascript"></script>
<script src="../js/loadText.js" type="text/javascript"></script>
<link href="../css/jquery/jquery-ui.css" rel="stylesheet" type="text/css">
<link href="../css/jquery/jquery-ui.theme.min.css" rel="stylesheet" type="text/css">
<link href="../css/jquery/jquery-ui.min.css" rel="stylesheet" type="text/css">
<link href="../css/jquery/jquery-ui.structure.css" rel="stylesheet" type="text/css">
<link href="../css/jquery/jquery-ui.structure.min.css" rel="stylesheet" type="text/css">
<link href="../css/jquery/jquery-ui.theme.css" rel="stylesheet" type="text/css">
<link href="../css/form/form.css" rel="stylesheet" type="text/css">
<title>Add</title>
</head>
<body>
<form:form modelAttribute="add" method="POST" name="add" action="${pageContext.request.contextPath}/add/myForm" id="myForm">
<fieldset>
<legend>Insert new:</legend>
<div id="id" class="element">
<label>ID:</label><br/>
<form:input path="id"/>
</div>
<div id="title" class="element">
<label>*Title:</label><br/>
<form:input path="title" required="required"/>
</div>
<div id="shortDescr" class="element">
<label>*Short Description:</label><br/>
<form:textarea path="shortDescr" rows="4" cols="50" required="required"/>
</div>
<div id="description" class="element">
<label>Description:</label>
<input type="file" value="Upload" id="file" accept=".txt"/><input type='button' id='load-file' value='Load'><br/>
<form:textarea path="description" rows="4" cols="50" placeholder="description"/>
</div>
<br/>
<br/>
<br/>
<br/>
<input type="submit" name="submit" value="Immetti">
</fieldset>
</form:form>
</body>
</html>
其他.js不接触说明。表单将数据发送到控制器,将结果包装在对象中。我使用jquery验证验证我的表单,如:Redirect in post mode inside a controller's method
搜索我如何更改textarea值上传文件我找到了这个很酷的解决方案:Get data from file input in JQuery并根据需要更改代码:https://jsfiddle.net/2madvyqb/7/
<input type="file" id="file" accept=".txt"/>
<input type='button' id='load-file' value='Load'>
<div id="file-content"></div>
<textarea id="description" name="description" rows="4" cols="50">
description</textarea>
并在js文件中用
替换结果$('textarea#description').text(fr.result);
它在jsfiddle中运行正常,但它在我的项目中不起作用。我没有在浏览器控制台中看到任何错误,在我看来,其他jquery * .js的顺序正确。
$('textarea#description').val(fr.result);
也不会工作。
我使用的是弹簧形式。