【发布时间】:2022-01-15 15:53:54
【问题描述】:
当我尝试运行我的 Spring 网页时,我的 JSP 页面出现错误。 错误是:
-
在第 [42] 行处理 [jsp/welcome.jsp] 时发生异常
-
org.apache.jasper.JasperException: 在 [42] 行处理 [jsp/welcome.jsp] 时发生异常
-
java.lang.IllegalStateException: Bean 名称“问题”的 BindingResult 和普通目标对象都不能用作请求属性
-
另一个错误是当我登录我的网络应用程序时,它仍然显示
http://localhost:8080/caseStudyNew/login而不是http://localhost:8080/caseStudyNew/welcome或http://localhost:8080/caseStudyNew/login/welcome
下面是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>Welcome</title>
<style>
* {
font-family: cursive;
}
body {
background-color: rgb(70, 187, 233);
}
</style>
</head>
<body>
<tr>
<td>Welcome ${firstname}</td>
</tr>
<br>
<tr>
<td><a href="home.jsp">Home</a></td>
</tr>
<h1 class="heading">Welcome</h1>
<h2 class="heading">Problem shared is a problem solved!</h2>
<form:form id="quesForm" modelAttribute="question" formactiom="question" method="post">
<table>
<tr>
<td>
<form:label path="ques">Enter Your Question</form:label>
</td>
<td>
<form:input path="ques" name="ques" id="ques" />
</td>
</tr>
<tr>
<td>
<form:label path="ques_desc">Add the Description</form:label>
</td>
<td>
<form:input path="ques_desc" name="ques_desc" id="ques_desc" />
</td>
</tr>
<tr>
<td>
<form:button id="ques_submit" name="submit">Ask!</form:button>
</td>
</tr>
</table>
</form:form>
</html>
控制器代码:
package jbr.springmvc.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import jbr.springmvc.model.Question;
import jbr.springmvc.service.UserService;
@Controller
public class QuestionController {
@Autowired
public UserService userService;
@RequestMapping(value = "/welcome", method = RequestMethod.GET)
public ModelAndView showRegister(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mav = new ModelAndView("welcome");
mav.addObject("question", new Question());
return mav;
}
@RequestMapping(value = "/welcome", method = RequestMethod.POST)
public ModelAndView addUser(HttpServletRequest request, HttpServletResponse response,
@ModelAttribute("question") Question question) {
userService.question(question);
return new ModelAndView("Hey your", "question", question.getQues());
}
}
型号代码
package jbr.springmvc.model;
public class Question {
private int quesid;
private String ques;
private String ques_desc;
public int getQuesid() {
return quesid;
}
public void setQuesid(int quesid) {
this.quesid = quesid;
}
public String getQues() {
return ques;
}
public void setQues(String ques) {
this.ques = ques;
}
public String getQues_desc() {
return ques_desc;
}
public void setQues_desc(String ques_desc) {
this.ques_desc = ques_desc;
}
}
【问题讨论】:
标签: java spring spring-mvc jsp