我必须在jsp页面的某些复选框内切换到选定的值,但在选择之后和按下"发送"按钮,我使用以下描述生成此错误:HTTP状态400:客户端发送的请求在语法上不正确。
我哪里错了?
TaskController.java
@RequestMapping(value="/newTask", method = RequestMethod.GET)
public String task(@ModelAttribute Task task, Model model) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String s = auth.getName();
Student student = studentFacade.retrieveUser(s);
List<Job> jobs = new ArrayList<>();
if(!(auth instanceof AnonymousAuthenticationToken)) {
jobs = facadeJob.retriveAlljobs();
model.addAttribute("job", getMathRandomList(jobs));
model.addAttribute("image", imageFacade.retriveAllImages());
List<Image> img = imageFacade.retriveAllImages();
task.setImages(img);
task.setStudent(student);
taskFacade.addTask(task);
List<Long> images = new ArrayList<>();
for(Image i : img)
images.add(i.getId());
model.addAttribute("images", images);
}
return "users/newTask";
}
@RequestMapping(value="/taskRecap", method = RequestMethod.POST)
public String taskRecap(@ModelAttribute Task task, Model model,BindingResult result) {
model.addAttribute("task", task);
return "users/taskRecap";
}
newTask.jsp
<form:form method="post" action="taskRecap" modelAttribute="task" name="form">
<form:checkboxes path="images" items="${images}" value="yes" />
<td><input type="submit" value="Send" /></td>
</form:form>
taskRecap.jsp
<c:forEach var="image" items="${task.images}">
<c:out value="${image.id}" />
</c:forEach>
Task.java
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
private Student student;
@ManyToMany
List<Image> images;
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public Task() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Task(Long id, Student student, List<Image> images) {
super();
this.id = id;
this.student = student;
this.images = images;
}
public List<Image> getImages() {
return images;
}
public void setImages(List<Image> images) {
this.images = images;
}
}
答案 0 :(得分:2)
使用查询参数
Function Merger(a(), b()) 'a has all lines, b doesn't, **first column is SORTED**
Dim i1&, i2&, j&, output
ReDim sortie(1 To UBound(a), 1 To UBound(a, 2) + UBound(b, 2) - 1)
i1 = 1: i2 = 1
Do While i2 < UBound(b) And i1 < UBound(a)
If a(i1, 1) = b(i2, 1) Then
For j = 2 To UBound(b, 2)
a(i1, UBound(a) + j - 1) = b(i2, j)
Next
i1 = i1 + 1
i2 = i2 + 1
ElseIf a(i1, 1) < b(i2, 1) Then
i1 = i1 + 1
Else
Stop 'either not sorted or not present in a
End If
Loop
Merger = output
End Function
使用隐藏变量。
<a href="edit.jsp?Name=${user.name}" />
如果您使用前两种方法中的任何一种,您可以像这样访问您的值:
<form method="post" action="update.jsp">
<input type="hidden" name="Name" value="${user.id}">
您可以发送使用会话对象。
String userid = session.getParameter("Name");
只要您的会话仍处于活动状态,现在可以从任何jsp获取这些值。
如果你使用第三个选项,你可以像这样访问你的值:
session.setAttribute("Name", UserName);