NullpointerException when I'm invoking a method - java

I have created an entity that selects all players from a database:
#NamedQueries({
#NamedQuery(name ="player.findAll",
query = "select p from Player p")
})
and then I have created a stateless bean and its interface that implements the method.
private EntityManager em;
...
public List<Player> findAllPlayers(){
TypedQuery <Player> query =
em.createNamedQuery("player.findAll", Player.class);
List<Player> results = query.getResultList();
return results;
}
and in interface its signature
public List<Player> findAllPlayers();
then I have created a stateless facade that works as a controller(MVC-structure).
#EJB
PlayerEAOLocal playerEAO;
...//Some more code
public List <Player> findAllPlayers(){
return playerEAO.findAllPlayers();
}
//And in interface...
public List <Player> findAllPlayers();
To make it clearer this is what I have done:
An entity
A local java bean(stateless) + Interface.
and a facade + Interface that refers to the beans.
Now I have created a servlet that the JSP will use for calling the FacadeLocal class(interface).
In my doPost method I have this implemented:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
FacadeLocal f = (FacadeLocal) facade.findAllPlayers();
request.setAttribute("facade", f);
}
and then I have the JSP file:
<form action = "GetAllPlayersServlet" method = "post">
<input type = "submit" name = "submit" value = "Show all"></input></td>
<td style = "width: 2px; "></td>
<% FacadeLocal facade = (FacadeLocal)request.getAttribute("facade"); %>
<td><input type = "text" name= "showAll" value = "<%= facade.findAllPlayers()%>">
But I get a nullPointerException
The error message
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/PlayerClientProject].[jsp]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet jsp threw exception: java.lang.NullPointerException
at org.apache.jsp.ShowAllPlayers_jsp._jspService(ShowAllPlayers_jsp.java:81)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
Alright. I am editing my question a little bit.
I have succeeded with showing all data from database in the servlet by doing:
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
List<Player> allPlayers = facade.findAllPlayers();
for (Player p1 : allPlayers) {
out.println("<h4>Founded: " + p1.getClass().getSimpleName());
out.println(" Id: " + p1.getId());
out.println(" - " + p1.getNickname());
out.println(" - " + p1.getLocation());
out.println(" - " + p1.getChampion() + "</h4>");
}
}
Now I wonder how I can pass the list to the JSP using doPost method?

You need to check facade for null:
<%
FacadeLocal facade = (FacadeLocal)request.getAttribute("facade");
if(facade == null)
{
out.print("<td><input type='text' name='showAll' value='' />");
}
else
{
out.print("<td><input type='text' name='showAll' value='"+facade.findAllPlayers()+"' />");
}
%>
If that doesn't fix it, do something similar everwhere you are using the dot operator on a variable that may be null.

Related

When try to upload many images with PrimeFaces <p:fileUpload > I get error

I've the following Jsf:
<!--******************* Button for adding other image ****************-->
<b:row styleClass="issuer_product_row">
<b:column col-lg="6" id="imageButton_insert" style="margin-bottom:10px;">
<h:commandButton id="addImageButton_insert" value=" Image(+) " action="#{cropImageIssuerBean.addImagesData()}">
<f:ajax execute="#this image_picker_insert" render="#this image_global_insert image_picker_insert" />
</h:commandButton>
<h:commandButton id="removeImageButton_insert" action="#{cropImageIssuerBean.removeImagesData()}" value="Image(-) ">
<f:ajax execute="#this image_picker_insert" render="#this image_global_insert image_picker_insert" />
</h:commandButton>
</b:column>
</b:row>
<!--******************* Selecting an image ************************-->
<b:row id="image_global_insert" styleClass="issuer_product_row">
<b:column col-lg="6">
<h:dataTable id="image_picker_insert" var="lpd" value="#{cropImageIssuerBean.lstOfImagesData}" width="100%" first="3">
<h:column col-lg="6">
<p:fileUpload id="uploadTag" styleClass="uploadTag" value="#{lpd.uploadedFile}" mode="simple" allowTypes="/(\.|\/)(gif|jpg|jpeg|gif|png|PNG|GIF|JPG|JPEG)$/" />
<div>
<img id="blah" src="#" alt="" />
</div>
</h:column>
<h:column col-lg="6">
<p:colorPicker id="color_picker_insert" value="#{lpd.key}" />
</h:column>
<h:column col-lg="6">
<!--******************* Resizing an image ************************-->
<h:inputHidden id="crop_image_ih" value="#{lpd.key_2}" />
</h:column>
</h:dataTable>
<p:commandButton value="Recadrer" action="#{cropImageIssuerBean.crop()}" ajax="false" />
</b:column>
<script>
var reader = new FileReader();
var $imageCrop = $('#blah').cropper({aspectRatio: 1.2, viewMode: 1, crop: function(e) { document.getElementById("issuer_product_add_product_form:crop_image_ih").value = e.x + '/' + e.y + '/' + e.width + '/' + e.height;}});
reader.onload = function (e) {
$imageCrop.cropper('replace', e.target.result); }
function readURL(input) {
if (input.files && input.files[0]) { reader.readAsDataURL(input.files[0]); }
}
$(".uploadTag").change(function(){
readURL(this); });
</script>
and the following bean class attribute and function that is used in my Jsf:
private List<KeyValueClass> lstOfImagesData;
public String crop() {
// System.out.println("imagecropproduct =
// "+cropImageProduct.getIdProduct());
Product prod = productServices.getOneProduct(cropImageProduct.getIdProduct());
String rootClass = "com/inductivtechnologies/quantitativemarketingwar/backingbeans/test/RegisterBean.class";
String path = UtilWebClass.getPathToWebinfFolder(rootClass);
Map<String, String> imgForColor = new LinkedHashMap<>();
for (KeyValueClass kvc : lstOfImagesData) {
if (kvc.getUploadedFile() != null) {
try {
// getting coord.
String nameFile = kvc.getKey_2();
String data[] = nameFile.split("/");
InputStream in = new ByteArrayInputStream(kvc.getUploadedFile().getContents());
String extension = FilenameUtils.getExtension(kvc.getUploadedFile().getFileName());
System.out.println("rect ======================== " + nameFile);
System.out.println("teamImg.getSize() ======================== " + kvc.getUploadedFile().getSize());
BufferedImage bImageFromConvert `enter code here`= ImageIO.read(in);
// line under this crops. It's possible there is a zoom to
// figure out, I didn't check yet. Seemed correct on first
// and only try. In any case you'll figure it out
// surely the parsing shouldn't be here but I need to sleep
// real bad.
BufferedImage croppedImage = bImageFromConvert.getSubimage((int) (Double.parseDouble(data[0])),
(int) (Double.parseDouble(data[1])), (int) (Double.parseDouble(data[2])),
(int) (Double.parseDouble(data[3])));
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(croppedImage, extension, os);
InputStream is = new ByteArrayInputStream(os.toByteArray());
String fileName = cropImageProduct.getIdProduct().toString() + "." + extension;
UtilWebClass.copyFile(UtilWebClass.setpathToImgUserFolder(path, fileName), is);
kvc.setKey_2(nameFile);
prod.setImage(fileName);
imgForColor.put(kvc.getKey(), kvc.getKey_2());
} catch (IOException e) {
}
}
}
prod.setImgForColor(imgForColor);
productServices.updateProduct(prod);
FacesMessage fm = new FacesMessage("Image modifiée avec succès");
FacesContext.getCurrentInstance().addMessage(null, fm);
return "productIssuer";
}
When clicking on the validation button that is used to crop and save uploaded images, I get the following error:
09:11:25,177 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/quantmarktest].[Faces Servlet]] (http-localhost-127.0.0.1-80-2) "Servlet.service()" pour la servlet Faces Servlet a généré une exception: javax.el.ELException: Cannot convert org.primefaces.model.UploadedFileWrapper#6e32afd0 of type class org.primefaces.model.UploadedFileWrapper to interface org.primefaces.model.UploadedFile
at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:420) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.parser.AstValue.setValue(AstValue.java:204) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:257) [jbossweb-7.0.13.Final.jar:]
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131) [jsf-impl-2.2.12.jar:2.2.12]
at javax.faces.component.UIInput.updateModel(UIInput.java:832) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIInput.processUpdates(UIInput.java:749) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIData.iterate(UIData.java:2028) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIData.processUpdates(UIData.java:1268) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIForm.processUpdates(UIForm.java:281) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1254) [jsf-api-2.2.12.jar:2.2]
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78) [jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) [jsf-impl-2.2.12.jar:2.2.12]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658) [jsf-api-2.2.12.jar:2.2]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:97) [primefaces-5.3.jar:5.3]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at com.inductivtechnologies.quantitativemarketingwar.test.filter.RestrictionFilter.doFilter(RestrictionFilter.java:88) [classes:]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:897) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:626) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2039) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]
I'll like someone to help me solving that error. Or give me any solution that can help me cropping and saving dynamically images.

org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException exception in jboss AS 7.1.1

I found an error org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException exception while deploying the war file.my code is as follows.
public class ReminderService extends HttpServlet implements Runnable{
public void init() throws ServletException {
LogMsg.info("I am init()");
ReminderService rThread = new ReminderService();
refresher = new Thread(rThread);
refresher.start();
LogMsg.info("I am from appointments refresh Method.Thread is started now");
}
#Override
public void run() {
try {
LogMsg.info("I am from run Method.");
obj.somefunction();
Thread.sleep(3000);
LogMsg.info("I am from run Method.Thread woke up from sleep");
}catch (InterruptedException e) {
e.printStackTrace();
}
run();
}
}
Here i want to call the this servlet class init() by default i mean while deploying the war file but the problem is it is not triggered automatically,please let me know i am new to this.
Here the problem is in run method when i tried to call any other methods it is raising the error as mentioned as below.Please let me know the wrong thing.Thanks in advance.
This is the message i got in console
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default- host].[/ThanQDoctor].[org.jboss.tools.thanqdoctor.rest.JaxRsActivator]] (http--127.0.0.1-8080-3) Servlet.service() for servlet org.jboss.tools.thanqdoctor.rest.JaxRsActivator threw exception: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:340) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:540) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.2.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67] Caused by: java.lang.NullPointerException

Neither BindingResult nor plain target object for bean name spring mvc

I have a problem with my little project.
Here is my controler
#Controller
#RequestMapping( "/loginPage" )
public class LoginController
{
private static final String VN_LOGIN_FORM = "login/LoginForm";
private static final String VN_HOME_FORM = "redirect:../home.html";
String VN_LOGIN_FAIL_FROM = "redirect:../loginPage /login.html";
// #Autowired
private AccountService act;
private EmployeeService em;
#RequestMapping( value = "login", method = RequestMethod.GET )
public String getRegistrationForm( Model model )
{
model.addAttribute( "user", new AccountForm( ) );
return VN_LOGIN_FORM;
}
#RequestMapping( value = "", method = RequestMethod.POST )
public String postRegistrationForm( #ModelAttribute( "user" ) AccountForm form )
{
Account temp = toAccount( form );
Account found = act.getAccount( temp.getUsername( ) );
java.util.List<Employee> list = em.getNewEmployees( );
if ( found != null && found.getPassword( ).equals( temp.getPassword( ) ) )
{
return VN_HOME_FORM;
}
return VN_LOGIN_FAIL_FROM;
}
#InitBinder
public void initBinder( WebDataBinder binder )
{
binder.setAllowedFields( new String[ ] { "username", "password", "confirmPassword", "firstName", "lastName", "email",
"marketingOk", "acceptTerms" } );
}
private static Account toAccount( AccountForm form )
{
Account account = new Account( );
account.setUsername( form.getUsername( ) );
account.setPassword( form.getPassword( ) );
return account;
}
}
Here is my jps page.
<form:form action="." modelAttribute="user" method="POST"
class="login">
<form:errors path="*">
<div class="warning alert">
<spring:message code="error.global" />
</div>
</form:errors>
<div>
<label for="username">${username}</label>
<form:input name="username" id="login" path="username"
cssErrorClass="short error" value="username" />
</div>
<br>
<div>
<label for="password">${password}</label>
<form:password path="password" name="password" value="1111111111" />
</div>
<div class="login-submit">
<button type="submit" value="" class="login-button">Submit</button>
</div>
<br>
<div class="forgot-password">
<button type="submit" class="btn-reset">Forgot your
password?</button>
<button type="submit" class="btn-reset">Reset</button>
</div>
</form:form>
Here is the exception trace:
09:31:49,069 ERROR [org.springframework.web.servlet.tags.form.InputTag] (http-localhost-127.0.0.1-8080-1) Neither BindingResult nor plain target object for bean name 'user' available as request attribute: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:164) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:127) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.apache.jsp.WEB_002dINF.views.login.LoginForm_jsp._jspx_meth_form_005finput_005f0(LoginForm_jsp.java:364)
at org.apache.jsp.WEB_002dINF.views.login.LoginForm_jsp._jspService(LoginForm_jsp.java:174)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) [jbossweb-7.0.13.Final.jar:]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1157) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:927) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Here is info from my beans-web.xml
<mvc:view-controller path="/loginPage/login.html" view-name="login/LoginForm" />
How i access the page :
http://localhost:8080/spring-mvc/loginPage/login.html
I don't understand where's the probleme.
Looks like you have configured only <mvc:view-controller> in your beans-web.xml. In order for spring to inject user object, the controller needs to be scanned as well. Below tags are required to register the controllers and the handler mapping. If you have configured the below post your complete config in your OP.
<mvc:annotation-driven/>
<context:component-scan base-package="you controller package goes here" />
If your dispatcher servlet is set to handle *.html, then you don't need <mvc:view-controller>. Simple passing through the controller should solve your issue.

Getting java.lang.ClassNotFoundException: javax.media.jai.ParameterBlockJAI exception

I am really stuck at this exception from 3 days. It was working fine but suddenly it is throwing this exception.
I am trying to upload an image for cleaning from my android device to JAVA servlet in jboss which is like this :
Class Servlet extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("You need to post an image.");
PrintWriter out = response.getWriter();
out.println("Please post an image..");
out.flush();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
long time = System.currentTimeMillis(); // check the time, for file-naming and such
System.out.println("Got a post - " + time);
try{
// get the image from the app
ObjectInputStream ois = new ObjectInputStream(request.getInputStream());
byte[] imageBytes = (byte[]) ois.readObject();
PlanarImage image = ImageUtil.getAsImage(imageBytes);
ois.close();
System.out.println("Read image from stream...");
// save a copy for inspection
ImageUtil.saveImage(image, time + "_y");
.......
And the ImageUtil.getasimage is like :
public static PlanarImage getAsImage(byte[] imageBytes){
BufferedImage bi = null;
InputStream in = null;
try {
in = new ByteArrayInputStream(imageBytes);
bi = ImageIO.read(in);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
return PlanarImage.wrapRenderedImage(bi);
}
I am getting the following error on the line
PlanarImage image = ImageUtil.getAsImage(imageBytes);
Error :
[org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/VINCServer].[vinc]] (http--0.0.0.0-8080-2) Servlet.service() for servlet vinc threw exception: java.lang.ClassNotFoundException: javax.media.jai.ParameterBlockJAI from [Module "deployment.VINCServer.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at VinCapture.doPost(VinCapture.java:41) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_55]
I have also downloaded all the needed jars for the above.
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import javax.media.jai.ParameterBlockJAI;
import javax.media.jai.PlanarImage;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.usaa.ar.deconvolution.Restore;
import com.usaa.ar.util.ImageUtil;
But still no luck.Please help me as I am not able to find anything on this exception.

CDI Servlet java.lang.NullPointerException

People, please, help me!!! I am driving really crazy. My code have been working before today, and now it's broken...
Here is my servlet:
#Stateless
class TempSession {
void createFile( String fileName ) {
try {
FileWriter writer = new FileWriter( fileName );
writer.close();
}
catch ( IOException e ) {
e.printStackTrace();
}
}
}
#WebServlet( name = "CreteFileServlet", urlPatterns = "/createCSV" )
public class CreateCSVConfigurationServlet extends javax.servlet.http.HttpServlet {
#Inject
TempSession session;
protected void doPost( javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response ) throws javax.servlet.ServletException, IOException {}
protected void doGet( javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response ) throws javax.servlet.ServletException, IOException {
session.createFile( "d:/session.txt" );
}
}
Here is web.xml:
<servlet>
<servlet-name>CreateFileServlet</servlet-name>
<servlet-class>com.bs.amg.test.servlets.CreateCSVConfigurationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CreateFileServlet</servlet-name>
<url-pattern>/createCSV</url-pattern>
</servlet-mapping>
JSP snippet:
<form action="createCSV" method="get">
<input type="submit" value="Create configuration"/>
</form>
Anв Jboss 7.0.1 log server snippet:
14:10:52,471 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "ear-1.0.ear"
14:11:10,336 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/web].[CreteFileServlet]] (http--127.0.0.1-8080-2) Servlet.service() for servlet CreteFileServlet threw exception: java.lang.NullPointerException
at com.bs.amg.test.servlets.CreateCSVConfigurationServlet.doGet(CreateCSVConfigurationServlet.java:136) [classes:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
Please, I really need your help!!!!!
You are declaring your servlet with both webservlet annotation and web.xml mapping. You should have only one declaration using the annotation as in this example.
I think that the injection is not occuring because CDI is not enabled. Make sure you have a beans.xml as stated in CDI documentation: http://docs.oracle.com/javaee/6/tutorial/doc/gjbnz.html. Here is a sample beans.xml file you can use to enable CDI:
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

Categories

Resources