netbeans.org のサンプル spring アプリケーションを参考にして、簡単なログインアプリケーションを作成してみました。実行すると、次のエラーが表示されます。
javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Neither BindingResult nor plain target object for bean name 'login' available as request attribute
ここに私のlogin.jspがあります
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Business SMS Login</title>
</head>
<body>
<div id="mainContainer">
<spring:nestedPath path="login">
<form name="frmBSMSLogin" action="" method="post">
<div id="controls">
<div id="lgnUsername">
<label for="txtUsername">Username</label>
<spring:bind path="login.username">
<input type="text" name="${status.expression}" value="${status.value}" id="txtUsername" maxlength="20" class="textInput"/>
</spring:bind>
</div>
<br/>
<div id="lgnPassword">
<label for="txtPassword">Password:</label>
<spring:bind path="login.password">
<input type="password" id="txtPassword" maxlength="20" name="${status.expression}" value="${status.value}" class="textInput"/>
</spring:bind>
</div>
</div>
<div id="submitSection">
<input type="button" value="Submit" class="buttonInput"/>
<input type="reset" value="Reset" class="buttonInput"/>
</div>
</form>
</spring:nestedPath>
</div>
</body>
ここに LoginController.java があります
package controller;
import org.springframework.web.servlet.mvc.SimpleFormController;
import java.net.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.portlet.ModelAndView;
import service.Login;
public class LoginController extends SimpleFormController {
private Login login;
public LoginController() {
setCommandClass(GetLoginDetails.class);
setCommandName("login");
setSuccessView("dashboard");
setFormView("index");
}
public void setLogin(Login login){
this.login = login;
}
protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)throws Exception {
//System.out.println("are we here?");
GetLoginDetails l = (GetLoginDetails) command;
ModelAndView mv = new ModelAndView(getSuccessView());
mv.addObject("helloMessage", login.authenticate(l.getUsername(),l.getPassword()));
return mv;
}
}
これは、applicationContext.xml です。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean name="login" class="service.Login"/>
</beans>
私は先週からずっとこのことをしていると思います。これは、netbeans の例を参照して行っています。リンクはhttp://netbeans.org/kb/docs/web/quickstart-webapps-spring.htmlです。これに対する解決策は見つかりませんでした。PHPのバックグラウンドから始めて、Springフレームワークが非常に難しいと感じていますが、全力で取り組んでいます。IDE として Netbeans を使用しています。それは良い選択ですか、それとも Eclipse が標準ですか? また、アプリケーションのデバッグ方法についてアドバイスをお願いします。PHP のような単純な echo または print_r は、ここではあまりにも贅沢に見えます :)
Ps 以前に同様の質問を投稿したことがあり、このあたりの誰かがコード ダンプであると不平を言い、私に反対票を投じました。巨大なコード ダンプがどこにあるのか、多くの質問がありますが、人々は親切に助けてくれました。したがって、これをコード ダンプまたは多少失礼な言葉だと考える人は、この質問に反対票を投じて貴重な時間を無駄にしないでください。私はここで助けを求める本物の学習者です