Javascript 如何在SpringMVC控制器中编写java脚本确认弹出框?
我正在用SpringMVC3编写一个文件上传程序 这是我的控制器类 我正在包括我的jsp页面Javascript 如何在SpringMVC控制器中编写java脚本确认弹出框?,javascript,java,spring-mvc,Javascript,Java,Spring Mvc,我正在用SpringMVC3编写一个文件上传程序 这是我的控制器类 我正在包括我的jsp页面 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/lo
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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">
<title>Insert title here</title>
<script>
function getChoice(){
var k=confirm("Do you want me to overwrite the existing file ?");
return k;
}
</script>
</head>
<body style="background-color:powderblue;color:Tomato">
<center><form method="POST" action="saveagain">
<h3>${message} </h3>
<br> <br>
<input type="hidden" name="fname" value="${filename}">
<input type="hidden" name="fcontent" value="${filecontent}"> <br><br>
<input type="button" value="Overwrite ?" onclick="choice=getChoice()"/>
<input type="submit" value="Submit ?"></form></center>
<br>
<br>
<center><b>${m}</b></center>
<br><br>
<center><a href="toupload">Click me to upload a file</a> <br><br>
<a href="uploadxml">Upload xml as text file</a> <br><br>
<a href="uploadcsv">Upload CSV as text file</a> <br><br>
<a href="uploadxls">Upload excel as text file</a> <br><br>
<a href="view">View files</a><br><br>
<a href="deletefiles">Delete multiple files</a></center>
</body>
</html>
在此处插入标题
函数getChoice(){
var k=confirm(“是否要我覆盖现有文件?”);
返回k;
}
${message}
${m}
如何将bean变量“choice”设置为确认弹出窗口的结果?试试这个
函数myFunction(){
var a=确认(“按下按钮!”);
控制台日志(a)
}
试试看
不确定在我的代码中建议的更改放在哪里。@sahiti var a有两个值true或false创建if块,如果值为true,则调用submitcall@NishalEdu抱歉nishal,还是不能。1). 建议的更改是在jsp页面中还是在控制器中?2) 如果在jsp页面中,如何将函数的返回值放入控制器中的变量中?
<%@ taglib prefix = "form" uri = "http://www.springframework.org/tags/form"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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">
<title>File Upload Example</title>
</head>
<body style="background-color:powderblue;color:Tomato">
<br>
<br>
<center><form:form action="savefile" method = "POST" modelAttribute = "fileUpload"
enctype = "multipart/form-data">
Please select a file to upload :
<input type = "file" name = "file" /><br><br><br>
<input type = "submit" value = "upload" />
<input type = "reset" value = "Reset" />
</form:form></center>
<br>
<br>
<br>
<center><b> ${message} </b></center>
<br>
<center> <a href="view">View files</a><br><br>
<a href="uploadxml">Upload xml as text file</a> <br><br>
<a href="uploadcsv">Upload CSV as text file</a> <br><br>
<a href="uploadxls">Upload excel as text file</a> <br><br>
<a href="deletefiles">Delete multiple files</a>
</center>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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">
<title>Insert title here</title>
</head>
<body style="background-color:powderblue;color:Tomato">
<center><form method="POST" action="saveagain">
<center><h3>${message}(Say yes\no)</h3></center>
<br>
<input type="text" name="choice">
<br><br>
<input type="hidden" name="fname" value="${filename}">
<input type="hidden" name="fcontent" value="${filecontent}">
<input type="submit" value="submit" /> </form></center>
<br>
<br>
<center><b>${m}</b></center>
<br><br>
<center><a href="toupload">Click me to upload a file</a> <br><br>
<a href="uploadxml">Upload xml as text file</a> <br><br>
<a href="uploadcsv">Upload CSV as text file</a> <br><br>
<a href="uploadxls">Upload excel as text file</a> <br><br>
<a href="view">View files</a><br><br>
<a href="deletefiles">Delete multiple files</a></center>
</body>
</html>
package com.fss;
public class Choice {
private boolean choice;
private String fname;
private String fcontent;
public boolean isChoice() {
return choice;
}
public void setChoice(boolean choice) {
this.choice = choice;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getFcontent() {
return fcontent;
}
public void setFcontent(String fcontent) {
this.fcontent = fcontent;
}
}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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">
<title>Insert title here</title>
<script>
function getChoice(){
var k=confirm("Do you want me to overwrite the existing file ?");
return k;
}
</script>
</head>
<body style="background-color:powderblue;color:Tomato">
<center><form method="POST" action="saveagain">
<h3>${message} </h3>
<br> <br>
<input type="hidden" name="fname" value="${filename}">
<input type="hidden" name="fcontent" value="${filecontent}"> <br><br>
<input type="button" value="Overwrite ?" onclick="choice=getChoice()"/>
<input type="submit" value="Submit ?"></form></center>
<br>
<br>
<center><b>${m}</b></center>
<br><br>
<center><a href="toupload">Click me to upload a file</a> <br><br>
<a href="uploadxml">Upload xml as text file</a> <br><br>
<a href="uploadcsv">Upload CSV as text file</a> <br><br>
<a href="uploadxls">Upload excel as text file</a> <br><br>
<a href="view">View files</a><br><br>
<a href="deletefiles">Delete multiple files</a></center>
</body>
</html>