Java exception problem - java

I got this exception in time of running a web application in java. What does this mean?
exception.name = javax.servlet.ServletException: BeanUtils.populate

I guess you are using something which utilizes Jakarta BeanUtils (like Struts) and some method is throwing an exception.
Following may be reasons for same :
The action attribute of an tag must
match exactly the path attribute of
the action definition in the
struts-config.xml file. This is how
Struts associates the ActionForm
bean with the action.
This error usually occurs when you
have specified a form name that does
not exist in your tag. For example,
you specifiec and 'myForm' is not
the name of a form associated with
myAction in the struts-config file
You get this message when Struts is
unable to map the data in the HTML
form to the properties in your
ActionForm bean. Make sure each of
the properties on your bean is
either a String or a boolean. Do you
have any properties of type
java.util.Date or other objects?
That might cause this error. Also
check to see that you have public
getters and setter for each of your
properties.
Check:
http://www.coderanch.com/t/53114/Struts/ServletException-BeanUtils-populate
http://forums.sun.com/thread.jspa?threadID=632599
http://javaexceptions1.blogspot.com/2009/08/javaxservletservletexception.html

A short call to google's famous www-indexer (with:"ServletException: BeanUtils.populate") provided this result:
ServletException BeanUtils populate
The answer to that question over there at coderanch could help to solve your problem

Since this is a Struts related exception (and seeing that we don't know the cause of the exception), here are some possible reasons why you're getting the exception.
No Bean Specified. This means that there is no ActionForm defined in your Action.
Your bean properties you're copying from doesn't match the bean properties you're matching to.
Unless we know the cause of the exception, you'll just have to debug your code and see what is the fault.

Related

Spring REST Docs throwing MustacheException

I am getting a weird exception with a trouble on non-existing field either on my response or request. I have configuration setup to generate snippets for response/requests on my endpoints with documentation on the fields of those beans. Except I am getting the following exception from org.springframework.restdocs.mustache package;
MustacheException$Context: No method or field with name 'required' on line 6
I have no 'required' field declared anywhere on my descriptor snippets, or within my request/response beans, and what is the deal with line 6? What a mysterious exception! What is the issue here?
The trouble stemmed from a custom request-parameters template, in src/test/resources/org/springframework/restdocs/templates/ resource folder. Due to the addition of a custom field within the template of request descriptor, the lack of this field was causing the issue. List 6 was where the 'request' field was being used within this file, thus the error.
Removing the custom template to let REST Docs use its default template resolved the issue.

EJB3 Interceptor- Setting attributes and reading them on JSP

In an enterprise application, I'm trying to set some attributes in an EJB3 interceptor and then show them on a jsp. Is it possible? How can I achieve that? The use case is as follows- Some values are read from the database which are required to be shown on the error page. This error page is the default error page, no controller for it. I couldn't find anything in the code regarding this error page, nothing in web.xml. Need a solution for this asap.
I couldn't find a way to use an interceptor. I ended up using a filter, which was already there in the application. I set an application scope variable map in the init method of the Filter. That ways, I had to get and set the values only once, i.e., at the server startup. Then I used this map in the JSP to read the values. Like, ${applicationScope.appParams.someKey}.

Primefaces 5 <p:ajaxExceptionHandler /> java.lang.Exception handling

When using
<p:ajaxExceptionHandler type="java.lang.Exception" >
or
<p:ajaxExceptionHandler type="java.lang.Throwable" >
the primefaces' exceptions handling mecanismm seems not working !!
My question is how can i use primefaces ajaxExceptionHandler to handle all the inhereted exceptions, no matter what exactely it is (NullPointerException, OutOfBoundException..etc) ?
i just have to mention that the <p:ajaxExceptionHandler> works fine when i use it with
javax.ejb.EJBException, java.lang.NullPointerException or other custom Exceptions.
Remove the type declaration so it's <p:ajaxExceptionHandler />
Also Omnifaces is good but, but obviously requires a new jar dependency, if PF now has the ability you may find it works for you. I however, like that Omnifaces is configured in web.xml and you can set it up to handle/cater for ajax and non ajax request with a page redirect.
This is new to PF5 so any issues let them know.
For more info see for usage
Jsf Ajax Error Handler Usage
Or
PF5 Exception Handler
If not defining a type doesn't work, ensure that in your WEB.XML has defined the error page for java.lang.Exception - if it's not defined there the type definition in your pages won't work.
After reading: PF5UG
I'm still not convinced either however - I will do some checks when i get home,.

ServletRequest.getRequestDispatcher() for non-existent files/resources

Currently I'm preparing for Java EE Web Component Developer exam.
In both exam study guide and Servlet API Java docs I found that method
ServletRequest.getRequestDispatcher()
returns
null if the servlet container cannot return a RequestDispatcher.
When I tried it with non-existent static file I actually got non-null value. And forward resulted in 404 sent to client. Same effect for non-existent servlet. I use Apache Tomcat 7.0.
Does it mean that this behaviour isn't defined and is left to implementer's choice? What do they (Java docs authors) mean by "servlet container cannot return a RequestDispatcher"? I tried to look for it in JSR spec but wasn't able to find answer.
This is what the Servlet 3.0 specification has to say about dispatcher behavior:
The getRequestDispatcher method takes a String argument describing a
path within the scope of the ServletContext. This path must be
relative to the root of the ServletContext and begin with a ‘/’, or
be empty. The method uses the path to look up a servlet, using the
servlet path matching rules in Chapter 12, “Mapping Requests to
Servlets”, wraps it with a RequestDispatcher object, and returns the
resulting object. If no servlet can be resolved based on the given
path, a RequestDispatcher is provided that returns the content for
that path.
Nowhere does it mentioning returning null if a matching servlet cannot be found for the dispatch path. Instead it states that the 'content' found at the dispatch path will be found, which I translate as meaning an implementation can simply allow the container to absolutely resolve the path (which in your scenario yields a 404).
As far as the Javadoc though, it seems documented with the broadest use case possible, aka, if the container cannot create a dispatcher for any reason then it will return a null object (as opposed to throwing an exception). This may be due to a technical problem in the implementation, or may be actually valid (e.g JAX-RS implementations can access some level of the Servlet infrastructure, but cannot use the servlet context or dispatcher).

JSP:forward Question

I am just getting started on web app development. I have an index.jsp that has just ONE line.
< jsp:forward page="landing.do?"/>
What does
the above line do?
page="landing.do?" actually refer to?
what does the question mark "?" next to "landing.do?" signify?
As Bozho rightly pointed out, a servlet called "action" is mapped to handle "*.do" in my web.xml (as shown below).
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
Now
How do I find out what the servlet "action" corresponding to "landing.do" actually does?
Thanks.
The <jsp:forward> forwards a client request to the url declared on the page attribute.
I also need to mention that in your example, you should have a / as first character inside your page declaration, if you want to specify a relative URL, i.e.:
This, in effect, is translated as a redirection to (if localhost)
http://localhost:8080/MyAPP/landing.do? (yours would have been translated to http://localhost:8080/MyAPPLanding.do?)
The ? allows you to append application/x-www-form-urlencoded parameters into your declaration.
More info here.
To know what landing.do does, do the following:
Go to your struts-config.xml (found in WEB-INF folder in your project) file and find any action (<action>) that a path="/landing") attribute.
Once you find your action, there's an attribute called type (inside that action). The type is a the class name of the action class that Struts calls to execute the action. The class name is fully qualified name.
Open the java file of the class (if it exists) and depending on the action (Action, DispatchAction, LookupDispatchAction), you will have to find its mappings and see what method Struts invokes.
In your example, my assumption will be based that your landing.do is of type Action. Therefore, read what the execute() method does. All actions actually, is execute() by Struts. The other actions are just Template Method patterns that knows what method to call by some mapping.
you probably have a servlet mapped to handle *.do in your web.xml
the ? means nothing here - generally it marks the start of get parameters (like ?param=value)
forward changes the current page with the specified, without the client knowing the change has happened.
This line will forward user to another page of the site, in particular to landing.do
page="landing.do?" actually refer to some page of the site landing.do. I believe this page is written with Struts framework. (But can be other)
what does the question mark "?" next to "landing.do?" mean nothing in this case. Generally after "?" there should be a list of request parameters. In this cases there will just be no parameters.
Update:
You should find servlet class which is mapped to that servlet name. After that you will be able to try to understand what that servlet class does. Also, look at the Struts tutorials or specification to get understanding of Struts framework workflows.

Categories