Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Hello World this week in the Python forum!

Malika Ben Aziz

Greenhorn
+ Follow
since Oct 26, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Malika Ben Aziz

Hi,
I had a project that was configured with ajax4jsf and I needed to use richFaces. When I added richfaces, I had exceptions caused by a conflict between my initial ajax4jsf and richfaces I have added...since richfaces has its own ajax4jsf. So I have commented some lines in my web.xml and it works fine.


Myy problem now is that i can't navigate from let's say users.xhtml to UserForm.xhtml when I click on the button on user.xhtml

Please can someone guess what I should add or comment to any xml file?

Thanks


This is my web.xml





9 years ago
JSF

Frits Walraven wrote:

I think the answer should be B, because it is attempting to access unauthorized resource. Can someone explain this?
Thanks a lot.


The important rule to follow here is that security only applies to requests coming from the client (browser). It doesn't apply to requests that are forwarded or included.

Regards,
Frits


I am sorry Frits, I still don't understand how to respond to this question. What I see is that we have a "manager" user that tries to access /jsp/protected.jsp
I still don't see what Forwarding or including have to do with this.

Could you please more explain why E is the correct answer?

Abimaran Kugathasan wrote:Thanks a lot Frits! I just guess it, but you gave the Specification. Thanks for conforming it! My doubt is clear now regarding EL!

Malika Ben Aziz wrote:
So If I understand you, it just knows that the string "true" is evaluated to the boolean true operator
Every thing else with double quotes is "false"

So ${"true" and "false"} is just like ${ true and "unknowStringWhichWillBeFalse"}

Am I correct?



Yea, It's in the Boolean.valueOf(String) method! If anything, other than true, will be false! It'll be safe for us!

Thanks to All!



It does the same for primitives


This will print 20


This will print 20 also

${"4" * "5"}

${"4" * "2.5"} ==> 20

I guess it's using Wrappers for everything between " "
Hi, I can't understand the response of this mock test from Ethunware(V4 -Standard Test 2 - Question 31 )


Consider the web.xml snippet shown in the exhibit.



Now consider the code for a jsp file named unprotected.jsp:




Which of the following statements hold true when unprotected.jsp is requested by an unauthorized user?

Select 1 correct option.
A.The user will be prompted to enter user name and password
B.An exception will be thrown
C.protected.jsp will be executed but it's output will not be included in the response
D.The call to include will be ignored
E.None of these


ANS : E

I think the answer should be B, because it is attempting to access unauthorized resource. Can someone explain this?
Thanks a lot.
Are you sure order is relevant?
Because on Hanumant Deshmukh Book, SCWCD EXAM STUDY KIT SECOND EDITION
chapter 17, question 3, page 467 I read this:

The <dynamic-attributes> element is set to true, so JSP statements
can incorporate variables beyond those mentioned in the TLD. If there are
static and dynamic values in a tag, the static values need to come first,



Frits Walraven wrote:Hi Abimaran,

If I correct, ${not map.d} will evaluate to ${not "1"}, and In logical operations, El treats the unknown variable as false. So not false = true!


It is a good explanation, here the lines in the specification to follow:

JSP.2.3.6.2 Unary not operator - {!,not} A
Coerce A to Boolean, apply operator


and if we Coerce A to a Boolean the following applies:

JSP.2.8.5 Coerce A to Boolean
• If A is null or "", return false
• Otherwise, if A is a Boolean, return A
Otherwise. if A is a String, and Boolean.valueOf(A) does not throw an exception return it
• Otherwise, error


So how does Boolean.valueOf() act in case of String which doesn't contain a boolean:

java.lang Class Boolean
public static Boolean valueOf(String s)
Returns a Boolean with a value represented by the specified string. The Boolean returned represents a true value if the string argument is not null and is equal, ignoring case, to the string "true".


It returns false for every String not equal to "true" (ignoring case)

and here you have your proof
Regards,
Frits



Thanks a lot
What surprised me is that it evaluates boolean operators with quotes.
For eg:

${map.a OR map.b} is like ${"true" or "false"} ==> true
${map.a AND map.b} is like ${"true" and "false"} ==> false

So If I understand you, it just knows that the string "true" is evaluated to the boolean true operator
Every thing else with double quotes is "false"

So ${"true" and "false"} is just like ${ true and "unknowStringWhichWillBeFalse"}

Am I correct?


Vijitha Kumara wrote:Best way to learn these is by testing these code yourself. And what you don't understand; the operators/keywords used?



I tested the first example



result :
true true

I don't understand why ${not map.d} gives true

map.d is "1", so ${not "1"} should logically give false

Another question please:

Given this URL

http://com.example/myServlet.jsp?number=three&number=four



Does these EL expressions give the same output?



=



=





Shoban Babu wrote:In custom tags, the <body-content> is mandatory.It takes one value from the following values: empty,scriptless,tagdependent or JSP.
<body-content>empty</body-content> means the tag must not have any body
<body-content>scriptless</body-content> means the tag must not have scripting elements
<body-content>tagdependent</body-content>means the tag body is treated as plain text
<body-content>JSP</body-content>means the tag body can have anything that can go inside a jsp


OK, thanks
but what id It's left empty

<body-content> </body-content>


What is the default value?
Hi,


In custom tags, the <body-content> is optional or mandatory?


what happens if I let it empty, like this <body-content></body-content>?
what is it's default value

Thanks


Hi folks



If we assume we're using java 1.4, is wrong because there is no autoboxing.

The exam title says Sun Certified Web Component Developer for the Java Platform, Enterprise Edition 5
But the jsp is 2.0 which is still java 1.4


On the real exam, what sohould I consider please?

Saurya Das wrote:All,
I would like to take this opportunity to thank all the people in this forum. I went to various posts to understand what resources i needed to prepare for the exam. I just read through Head First Servlets and 3 days before the exam i took the Enthuware exams. Completed the exam in an hour. I am happy with the results.

Thanks again!!
Saurya



Congrats!!
How did you prepared for the exam?
9 years ago
Hello folks
I am preparing for SCWCD using the book SCWCD EXAM STUDY KIT 2nd edition (SCE 310-081).

On the chapter about Servlets, there is a response for a question that did not convince me.




the explanation seems correct, but the answer is not.

I didn't find any thing about headers on the ServletRequest interface.
To me correct answer would be just "e"

Can you confirm please?


Hi
I 'm trying to run a simple example of adding a pojo with spring and jpa, but had and exception
these are my files:

******************************************************

-----------
Product
-----------


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.alcatel.model;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;


@Entity
public class Product extends BaseObject implements Serializable {
private Long id;
private String name;
private String description;

public String getDescription() {
return description;
}

@Id @GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}

public String getName() {
return name;
}

public void setDescription(String description) {
this.description = description;
}

public void setId(Long id) {
this.id = id;
}

public void setName(String name) {
this.name = name;
}

public Product() {
}



@Override
public String toString() {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public boolean equals(Object o) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int hashCode() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
*******************************************************


------------
ProductDao
-----------


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.alcatel.dao;


import com.alcatel.model.Product;
import java.util.List;


public interface ProductDao extends GenericDao<Product, Long>{
public List<Product> findByName(String name);
}

****************************************************


------------
ProductDaoTest
-------------

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.alcatel.dao;

import com.alcatel.model.Product;
import java.util.List;
import javax.persistence.EntityNotFoundException;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;


public class ProductDaoTest extends BaseDaoTestCase {

@Autowired
private ProductDao productDao = null;

public void setProductDao(ProductDao productDao) {
this.productDao = productDao;
}

@Test
public void testFindProductByName() throws Exception {
List<Product> produit = productDao.findByName("Raible");
assertTrue(produit.size() > 0);
}

@Test
public void testAddAndRemoveProduct() throws Exception {
Product product = new Product();
product.setName("John");
product.setDescription("Elway");

product = productDao.save(product);

assertEquals("John", product.getName());
assertNotNull(product.getId());

log.debug("removing product...");

productDao.remove(product.getId());

try {
productDao.get(product.getId());
fail("Product found in database");
} catch (EntityNotFoundException enf) {
log.debug("Expected exception: " + enf.getMessage());
assertNotNull(enf);
}
}

}
-------------------------------------------------------------

and finally, my 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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
default-lazy-init="true">

<!-- Activates scanning of @Autowired -->
<context:annotation-config/>

<!-- Activates scanning of @Repository and @Service -->
<context:component-scan base-package="com.alcatel"/>

<!-- Add new DAOs here -->

<bean id="productDao" class="com.alcatel.dao.jpa.GenericDaoJpa">
<constructor-arg value="com.alcatel.model.Product"/>
</bean>

<!--<bean id="productDao" class="com.alcatel.dao.jpa.GenericDaoJpa"/>-->

<!-- Add new Managers here -->
</beans>

******************************

I have this exception:



Test set: com.alcatel.dao.ProductDaoTest
-------------------------------------------------------------------------------
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.03 sec <<< FAILURE!
testFindProductByName(com.alcatel.dao.ProductDaoTest) Time elapsed: 0.018 sec <<< ERROR!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alcatel.dao.ProductDaoTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.alcatel.dao.ProductDao com.alcatel.dao.ProductDaoTest.productDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.alcatel.dao.ProductDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:333)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.alcatel.dao.ProductDao com.alcatel.dao.ProductDaoTest.productDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.alcatel.dao.ProductDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:504)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:280)
... 30 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.alcatel.dao.ProductDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:896)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:765)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:680)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:475)
... 32 more

testAddAndRemoveProduct(com.alcatel.dao.ProductDaoTest) Time elapsed: 0.004 sec <<< ERROR!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alcatel.dao.ProductDaoTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.alcatel.dao.ProductDao com.alcatel.dao.ProductDaoTest.productDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.alcatel.dao.ProductDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:333)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.alcatel.dao.ProductDao com.alcatel.dao.ProductDaoTest.productDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.alcatel.dao.ProductDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:504)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:280)
... 30 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.alcatel.dao.ProductDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:896)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:765)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:680)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:475)
... 32 more
-----------------------------------

Could you please help me finding what's wrong?

Thanks
« Return to AppFuse - User | 6 views
Free Embeddable Forum Powered by Nabble Help
9 years ago