标签: javabeans

在Servlet中使用JSP Bean

所以我在JSP页面上使用bean来存储一些数据,如下所示:

<jsp:useBean id="data" class="myclass" scope="session" />

无论如何在以后的同一会话中从servlet访问这个bean?

编辑:

显然我在加载jsp页面和servlet时没有访问同一个会话.我打印出会话ID,它给了我两个页面的不同值,所以我无法访问bean.有任何想法吗?

java jsp servlets javabeans

0
推荐指数
1
解决办法
2075
查看次数

Spring框架问题

这些天Spring很好用.春天是否有任何不足之处.它可以处理非常重的负载吗?

java spring javabeans

0
推荐指数
1
解决办法
128
查看次数

术语:实例变量的单字Java术语?

我正在寻找在类(非静态)中声明的实例变量的替代OO/Java术语,或者更具体地说,在使用JPA注释"装饰"的Java类中:

@Entity
@Table(name = "Departments")
@IdClass(value = DepartmentId.class)
public class Department implements Serializable
{
    @Id
    @Column(name = "company_id", insertable = false, updatable = false)
    private Integer companyId;

    @Id
    @Column(name = "internal_code")
    private String internalCode;

    @Column(name = "name")
    private String name;

    @ManyToOne
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    private Company company;

    ...
}
Run Code Online (Sandbox Code Playgroud)

他们被称为财产吗?属性?会员?场?只是参考?除了实例变量之外什么都没有?

如果有的话,我想听一个单词的用语."实例变量"对于我目前正在做的事情来说太长了.

java jpa terminology instance-variables javabeans

0
推荐指数
1
解决办法
276
查看次数

将其他bean从xml定义注册到已初始化的应用程序上下文中

我已经初始化了一个应用程序上下文,我还需要从xml定义中加载另一个bean.

我可以执行applicationContext.getAutowireCapableBeanFactory(),但它只适用于某些Object的自动装配属性.

我无法通过XmlBeanDefinitionReader和ContextLoader找到如何做到这一点,因为正如您所看到的,只有公共方法是loadContext(String... locations),它总是创建一个新的上下文.

public final ConfigurableApplicationContext loadContext(String... locations) throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("Loading ApplicationContext for locations [" +
                StringUtils.arrayToCommaDelimitedString(locations) + "].");
    }
    GenericApplicationContext context = new GenericApplicationContext();
    prepareContext(context);
    customizeBeanFactory(context.getDefaultListableBeanFactory());
    createBeanDefinitionReader(context).loadBeanDefinitions(locations);
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    customizeContext(context);
    context.refresh();
    context.registerShutdownHook();
    return context;
}
Run Code Online (Sandbox Code Playgroud)

java spring javabeans

0
推荐指数
1
解决办法
2260
查看次数

Spring:通过ApplicationContext访问主bean

如果我的ApplicationContext中有2个bean实现相同的接口,我可以在bean定义中将其中一个标记为primary.这个bean更适合依赖注入.

有没有办法使用ApplicationContext直接访问主要的没有DI?

java spring dependency-injection javabeans autowired

0
推荐指数
1
解决办法
5308
查看次数

Spring上下文XML中未解析属性

我正在一个static main方法中创建我的Spring上下文

return new ClassPathXmlApplicationContext("applicationContext.xml");
Run Code Online (Sandbox Code Playgroud)

在里面applicationContext.xml我用我的豆子连线

<bean id="dataSource" 
    class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
    <property name="driverClassName">
        <value>${db.driverclassname}</value>
    </property>
    ...
</bean>
Run Code Online (Sandbox Code Playgroud)

.properties我的类路径上有一个包含值的文件db.driverclassname.

不幸的是我收到以下错误:

Property 'driverClassName' threw exception; 
    nested exception is java.lang.IllegalStateException: 
        Could not load JDBC driver class [${db.driverclassname}]
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我正在使用Spring 2.5.5

java spring properties javabeans

0
推荐指数
1
解决办法
1144
查看次数

无法创建托管bean UserBean - JSF

我正在尝试创建一个访问数据库的简单登录页面,以便在验证用户名和密码时,在类中设置id,firstName,lastName以进行访问.我收到此错误:

javax.servlet.ServletException: Unable to create managed bean UserBean.  The following problems were found:
 - Property firstName for managed bean UserBean does not exist.  Check that appropriate getter and/or setter methods exist.
 - Property id for managed bean UserBean does not exist.  Check that appropriate getter and/or setter methods exist.
 - Property lastName for managed bean UserBean does not exist.  Check that appropriate getter and/or setter methods exist.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
Run Code Online (Sandbox Code Playgroud)

我有id,firstName,lastName但没有setter的getter,因为它们是在验证后设置的.

这是类UserBean

public class UserBean {
private static String password, username, id, …
Run Code Online (Sandbox Code Playgroud)

jsf properties javabeans

0
推荐指数
1
解决办法
2万
查看次数

无法在applicationContext.xml文件中导入persistence.xml

我正在使用eclipse juno IDE我有Java应用程序,它有src文件夹.在我的文件夹中:

1)applicationContext.xml

2)persistence.xml

我也有DBInterface,我用JPA实现它.现在在applicationContext.xml文件中,我有一个用于JPA实现的bean.

当我尝试注入bean时,我得到了一个类似"找不到持久性提供程序"的删除.

所以我尝试在applicationContext文件中导入持久性文件,但是我得到了另一个例外.

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:aop="http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
   xmlns:context="http://www.springframework.org/schema/context/spring-context-2.5.xsd"
   xmlns:flow="http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd"
   xmlns:jms="http://www.springframework.org/schema/jms/spring-jms-2.5.xsd"
   xmlns:jee="http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"
   xmlns:lang="http://www.springframework.org/schema/lang/spring-lang-2.5.xsd"
   xmlns:osgi="http://www.springframework.org/schema/osgi/spring-osgi.xsd"
   xmlns:tx="http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
   xmlns:util="http://www.springframework.org/schema/util/spring-util-2.5.xsd"
   xmlns:p="http://www.springframework.org/schema/p"

   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/aop/spring-aop-2.5.xsd/spring-spring-aop-2.5.xsd-2.5.xsd
      http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/context/spring-context-2.5.xsd/spring-spring-context-2.5.xsd-2.5.xsd
      http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd/spring-spring-webflow-config-1.0.xsd-2.5.xsd
      http://www.springframework.org/schema/jms/spring-jms-2.5.xsd http://www.springframework.org/schema/jms/spring-jms-2.5.xsd/spring-spring-jms-2.5.xsd-2.5.xsd
      http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/jee/spring-jee-2.5.xsd/spring-spring-jee-2.5.xsd-2.5.xsd
      http://www.springframework.org/schema/lang/spring-lang-2.5.xsd http://www.springframework.org/schema/lang/spring-lang-2.5.xsd/spring-spring-lang-2.5.xsd-2.5.xsd
      http://www.springframework.org/schema/osgi/spring-osgi.xsd http://www.springframework.org/schema/osgi/spring-osgi.xsd/spring-spring-osgi.xsd-2.5.xsd
      http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/tx/spring-tx-2.5.xsd/spring-spring-tx-2.5.xsd-2.5.xsd
      http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/util/spring-util-2.5.xsd/spring-spring-util-2.5.xsd-2.5.xsd">


    <bean id="JPA"  class="pack.jpa.JPAQueries"/>
    <import resource="persistence.xml"/>
</beans>
Run Code Online (Sandbox Code Playgroud)

persistence.xml中

<?xml version="1.0" encoding="UTF-8"?>
<persistence xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 

http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> 
         <persistence-unit transaction-type="RESOURCE_LOCAL" name="MyJPA"> 
             <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
             <class>pack.bl.Travels</class>
             <class>pack.bl.Example</class> 
             <properties> <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/> 
                 <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/taxis"/> 
                 <property name="javax.persistence.jdbc.password" value=""/> 
                 <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> …
Run Code Online (Sandbox Code Playgroud)

spring persistence jpa javabeans applicationcontext

0
推荐指数
1
解决办法
1万
查看次数

会话范围bean - 如何处理多用户数据

我使用JSF 2.0创建了一个Web应用程序.我到处都使用会话范围bean,因此我遇到了问题.:(我将用下面的例子解释.

我有dataTable中的用户列表.当我点击用户时,我会看到该用户的详细信息.现在,当我右键单击用户A并单击时Open in new tab,我会在新选项卡中看到用户A的详细信息.

现在,当我右键单击用户B并单击在新选项卡中打开时,我会看到用户B的详细信息.

但是,当我进入选项卡(用户A详细信息在那里)并刷新该页面时,我会看到用户B的详细信息.

如何克服这一点,以便如果我刷新页面,我仍然会看到用户A而不是用户B的详细信息.

java jsf javabeans session-scope jsf-2

0
推荐指数
1
解决办法
938
查看次数

JavaBean上的Oracle文档可能是错误的吗?

在此JavaBeans上的Oracle文档中,我们看到:

public class FaceBean {
    private int mMouthWidth = 90;

    public int getMouthWidth() {
        return mMouthWidth;
    }

    public void setMouthWidth(int mw) {
        mMouthWidth = mw;
    }
}
Run Code Online (Sandbox Code Playgroud)

不应该是财产mouthWidth吗?

java javabeans

0
推荐指数
1
解决办法
22
查看次数