I am trying to create a sample registration page with Spring MVC and JSP pages.
While opening the url on tomcat server, I am getting following error
root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'register' available as request attribute
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(
I have a JSP register.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"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Registration</title>
</head>
<body>
<form:form action="/register/process" method="POST" modelAttribute="register">
<table style="text-align: center;">
<tr>
<td><form:label path="fname">First Name</form:label></td>
<td><form:input path="fname" name="fname"
id="fname" /></td>
</tr>
<tr>
<td><form:label path="lname">Last Name</form:label></td>
<td><form:input path="lname" name="lname" id="lname" />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="CREATE AN ACCOUNT"/>
</td>
</tr>
</table>
</form:form>
</body>
</html>
I have a controller class UserController.java
package vnfhub.supplier.controller;
#Controller
public class UserController {
#RequestMapping(value = "/register", method = RequestMethod.GET)
public String getRegisterForm(Model model) {
model.addAttribute("register", new Register());
return "register";
}
#RequestMapping(value = "/register/process", method = RequestMethod.POST)
public String processRegistration(#ModelAttribute("register") Register register, BindingResult result) {
return "success";
}
}
and a success.jsp page
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Success Form</title>
</head>
<body>
<font color="green"><h1>Hello</h1></font>
<h1>You have successfully registered</h1>
<font color="green"><h1>Welcome to Spring world !</h1></font>
</body>
</html>
I have tried many solution on stackoverflow.... but none of them worked.
I find your code okay so far as you given here. I mimic the situation with your code but unfortuantely found No Exception.
Things that you might have doing wrong is you are running some old build code in your tomcat. try to clean build and re-deploy in your container.
NB: one friendly suggestion. You are doing one thing wrong that is having action of your form to /register/process that will send the request to the container root (e.g. localhost:8080/register/process). And you will get 404 for that. You are not probably want that. register/process should be your URL and this will POST the request relative to your application-context. If your application context is something localhost:8080/test, this will send the request to localhost:8080/test/register/process
Related
I have Simple Spring form with employee personal info and Contact Info..I have 2 bean EmpPersonalInfo and EmpContactInfo,How do i bind 2 object with "command' and show in empform.
i got this error like Invalid property 'name' of bean class [java.util.HashMap]: Bean property 'name' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
empform
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form:form action="saveemp" method="post">
<table>
<tr> <td> Name</td>
<td> <form:input path="name"/></td></tr>
<tr> <td>Id </td>
<td><form:input path="id"/> </td></tr>
<tr><td> Current Address</td>
<td><form:input path="empcontactinfo.currentAddress"/> </td> </tr>
</table>
<input type="submit" value="Submit">
</form:form>
</body>
</html>
Empcontroll.class
#RequestMapping("/empform")
public ModelAndView showForm()
{
Map<String,Object> modelmap=new HashMap<String,Object>();
modelmap.put("personalinfo",new EmpPersonalInfo() );
modelmap.put("contactinfo", new EmpContactInfo());
return new ModelAndView("empform","command",modelmap);
}
Path attribute puts value of input field into java properties using java beans convention to be used as #ModelAttribute in your controller method.
#RequestMapping(...)
public String saveEmp(#ModelAttribute("employee") EmpPersonalInfo employee) {
// ...
}
if you just want to display the values inside these two objects in that map, you could use,
<c:out value="${command['contactinfo'].contact}"/>
This question already has an answer here:
How do I pass current item to Java method by clicking a hyperlink or button in JSP page?
(1 answer)
Closed 6 years ago.
I want to perform multiple operation Like DELETE and UPDATE to do so I Need to send Data to Controller,
where I Am doing Mistake??
Following is my JSP page
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:useBean id="TimeDetailBean" class="com.logic.bean.userBean" scope="application" />
<!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>Manage Results</title>
</head>
<body>
<center>
<h1>The Employee_Info Results </h1>
<table>
<tr><th>Name</th><th>Last name</th><th>Password</th></tr>
<c:forEach items="${rows}" var="row">
<tr>
<td><input type="text" name="name" value=${row.NAME}></td>
<td><input type="text" name="lastname" value=${row.LASTNAME}></td>
<td><input type="text" name="password" value=${row.PASSWORD}></td>
<td>UPDATE</td>
<td>DELETE</td>
</tr>
</c:forEach>
</table>
</center>
</body>
</html>
and below is the controller where I want The value of name ,lastname and password
#RequestMapping("/delete")
public ModelAndView Delete(HttpServletRequest request, HttpServletResponse response)
{
System.out.println("Delete Controller Executed");
userBean ub= new userBean();
Dao d= new Dao();
String name=request.getParameter("name");
String lastname=request.getParameter("lastname");
System.out.println("Name catch"+name);
System.out.println("Lastname catch"+lastname);
return new ModelAndView("deleteSuccess");
}//delete ends
Thanks in advance. .
In order to send the Data from JSP to Controller
Create a form with action (/delete) and method=POST
Create a Controller with the #RequestMapping("/delete") that point to form action
Use Request.getParameter("name") in Controller.
Now on submit button in the JSP Spring Servlet Dispatcher will the mapping form in the Controller class and send the data to the controller from JSP.
Let us know if more inforamtion needed I will share the sample example
Regards,
Pavan
I have a problem with JSP Bean's scope - Request. I have a page Index.jsp with jsp bean 'message', its scope is Request and a page result.jsp. When I send request to result.jsp from Index.jsp. My bean 'message' should keep its value but it doesn't now.
I tried with scope Session and my bean worked well. I search all questions about this problem but no answer can meet my question.
Here is my code:
file Index.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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=UTF-8">
</head>
<body>
<%
String name = request.getParameter("name") == null ? "" :
request.getParameter("name");
int age = ( request.getParameter("age") == null ||
request.getParameter("age") == "") ? 0 :
Integer.parseInt(request.getParameter("age"));
%>
<h1>Nice to meet you</h1>
<form method="post" action="View/result.jsp">
<jsp:useBean id="message" class="com.java.Message" scope="request"/>
<jsp:setProperty name="message" property="message" value="Hello world!"/>
<label>Name: </label> <br>
<input type="text" name="name" placeholder = "Phan Dinh The"/> <br>
<label>Age: </label> <br>
<input type="number" name="age" placeholder = "25"/> <br>
<input type="checkbox" name="title"/> Senior <br>
<input type="radio" name="language" value="c#"/> C# <br>
<input type="radio" name="language" value="java"/> Java <br>
<br><br>
<jsp:include page="View/date.jsp" flush="true"/>
<input type="submit" value="submit"/>
<br><br>
</form>
<br><br>
</body>
</html>
file result.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="com.java.Message"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="message" class="com.java.Message" scope="request"/>
<jsp:getProperty name="message" property="message"/>
</body>
</html>
my class Message
package com.java;
public class Message {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String content) {
this.message = content;
}
}
I use Tomcat 8.0.23, Jsp version 2.3, Servlet API 3.1
When you use
<jsp:setProperty name="message" property="message" value="Hello world!"/>
in the index.jsp file, that property is scoped to the request of the index.jsp page. once the index jsp page returns to the client, that request is done. When you submit the form, a new request is created, and that is used for the result page generation. Thus when you are in the result.jsp code, there is no request scoped parameter named 'message'.
You could always put the message in an
<input type="hidden" name="message">Hello World</input>
field of the form, and retrieve it in the results.jsp that way.
I am working on designing a web application using Java servlets and JSP and am having issues getting the JSP file to include the CSS file. Each JSP page that is called up includes references to header and footer JSP files and the header file includes the with link to the CSS. All of these files are in a secure resource folder "proforma" within my web application. Prior to trying to include the CSS, the security and the header/footer inclusions were working fine, and continue to do so - they are just not formatted per the CSS.
I have the CSS reference included in a header file as follows:
header.jsp
<%#page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="${pageContext.request.contextPath}/proforma/cssGuide.css" type="text/css"/>
<title>Pro Forma</title>
</head>
<body>
<h1>Pro Forma</h1>
When I use the pageContext Expression Langugae (${}) like the above, the page content that is loaded is the actual CSS content itself, not the actual content I am looking for.
However, if I use the following JSP code, I get the correct HTML content and the browser source review shows the loaded correctly, but there is no CSS source code:
Alternative header.jsp file (ProForma is the name of the application):
<%#page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../ProForma/proforma/cssGuide.css" type="text/css"/>
<title>Pro Forma</title>
</head>
<body>
<h1>Pro Forma</h1>
Here is a sample content page that I am trying to format:
<%#include file="../proforma/header.jsp" %>
<table>
<tr>
<td>
${createProjectResponse}
</td>
</tr>
<tr>
<td>
<form action="/ProForma/downloadInput" method="post">
<input type="submit" name="downloadInputButton" value="Download Input File" class="controlCenterButton"/>
</form>
</td>
</tr>
<tr>
<td>
<form action="/ProForma/AddProject" method="post">
<input type="hidden" name="actionValue" value="addProject"/>
<input type="submit" name="addPortfolioSubmit" value="Add Project" class="controlCenterButton"/>
</form>
</td>
</tr>
<tr>
<td>
<form action="/ProForma/SelectProjectController" method="post">
<input type="hidden" name="actionValue" value="selectProject"/>
<input type="submit" name="selectProjectSubmit" value="Select Project" class="controlCenterButton"/>
</form>
</td>
</tr>
</table>
<%#include file="../proforma/footer.jsp" %>
Here is the CSS file (very simple at this point until I get it working):
input.controlCenterButton{
width: 20em;
height: 2em;
}
For what it is worth, here is the footer.jsp file:
<p id="footer_p">Company</p>
</body>
</html>
Is there something that I am missing that is preventing the CSS file from being included? I appreciate any help.
I'm brand new to the javascript. I'm trying to call a javaScript function from my jsp.Its not working. I was trying to debug it through bugzila. It saying "No Javascript on this page"
<%# 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>
<script type="text/javascript" src="ajaxs.js"></script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<%
out.println("Bismillahir Rahmanir Rahim");
%>
<jsp:useBean id="numBean" class="beans.NumberBean">
<jsp:setProperty name="numBean" property="*" />
</jsp:useBean>
<form action="index.jsp" method="post">
<table>
<tr>
<td>Enter Integers:</td>
<td><input type="text" id="inputString" name="inputString"
value="<jsp:getProperty name="numBean" property="inputString" />"
/> </td>
<td>(Use semi-colon to separate number)</td>
</tr>
<tr>
<td>M - number of largest element to find.:</td>
<td>
<input type="text" id="nthHighest" name="nthHighest"
value="<jsp:getProperty name="numBean" property="nthHighest" />" />
</td>
</tr>
</table>
<input type="submit" value="Identify" onclick="ajaxFunction()" />
<div id="result"></div>
</form>
</body>
</html>
I'm trying to call "ajaxFunction()" on onclick event.
I included js file as following at the top:
<script type="text/javascript" src="ajaxs.js"></script>
can u pls help me to identify what I'm doing wrong here...
Thanks in advance
Try with including script tag with "src="ajaxs.js" (your current script that including "src="ajaxs.js") within head tag.The contents within head tag load at the loading page .
thanks....