get/setAttribute()
你从请求和来自之间调用它们之间的区别是什么getServletContext()
.我注意到你需要
RequestDispatcher rd = request.getRequestDispatcher("/view.jsp");
rd.forward(request, response);
Run Code Online (Sandbox Code Playgroud)
要求工作,但您只需要导航到应用程序中的另一个jsp或servlet即可使用getServletContext().getAttribute()
.
但我不明白背后发生了什么.
我正在尝试运行一个简单的 Hibernate 应用程序,但出现此错误:
org.hibernate.exception.SQLGrammarException: could not execute query
java.sql.SQLException: ORA-00942: table or view does not exist
Run Code Online (Sandbox Code Playgroud)
我的实体:
package beans;
import javax.persistence.*;
@Entity
public class Idt {
@Id
private int id;
@Column(name="name")
private String name;
public Idt(){
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
我的表在 Hr 用户中称为 IDT。
CREATE TABLE "HR"."IDT"
(
"ID" NUMBER …
Run Code Online (Sandbox Code Playgroud) 我是EJB的新手,我正在尝试理解Stateless和Stateful bean之间的差异,所以我做了一个简单的例子来测试它们.
@Stateless
public class Service {
private int num;
public Service(){
}
public int getNum() {
return num;
}
public void setNum() {
this.num++;
}
}
Run Code Online (Sandbox Code Playgroud)
@WebServlet("/Controller1")
public class Controller1 extends HttpServlet {
@EJB
private Service serv;
public Controller1() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
serv.setNum();
response.getWriter().println(serv.getNum());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
Run Code Online (Sandbox Code Playgroud)
和有状态的等价物:
@Stateful
public class ServiceStateful implements Serializable{ …
Run Code Online (Sandbox Code Playgroud) 我有石英库的问题.我在春季2.5使用它:
<bean id="reminderBean" class="com.mail.timexis.ReminderBean">
<property name="mailSender">
<ref local="timexisMailSender" />
</property>
</bean>
<bean id="jobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="reminderBean" />
<property name="targetMethod" value="execute" />
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<!-- run every morning at 6 AM -->
<property name="cronExpression" value="* * * * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
Maven的:
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.4</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我运行tomcat时,它无法实例化"jobDetail"bean,因为它无法看到MethodInvokingJobDetailFactoryBean类使用的JobDetail类 ( Caused by: java.lang.NoClassDefFoundError: org/quartz/JobDetail)
Maven下载了jar,我可以在MavenDependencies下看到它,我可以找到JobDetail类.
我认为它与弹簧2.5和石英的兼容性有关.有任何想法吗?
public class Base{
protected String str;
public static final Base ERROR = new Base("error");
...
}
public class Derived extends Base{
public static final Derived OTHER = new DERIVED("other");
public Derived(String str) {
super(str);
}
}
Derived page = Derived.OTHER; //OK
page = (Drived)Derived.ERROR; //ClassCastException
Run Code Online (Sandbox Code Playgroud)
那么我可以将静态成员变量从Base转换为Derived类吗?
根据Spring 文档,JDBCTemplate 类“可以通过使用 DataSource 引用直接实例化在服务实现中使用,或者在应用程序上下文中做好准备并作为 bean 引用提供给服务”。
public class JdbcCorporateEventDao implements CorporateEventDao {
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道,与在上下文中定义jdbctemplate
为单例并直接将其注入到Dao
public class JdbcCorporateEventDao implements CorporateEventDao {
@Autowired
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
}
Run Code Online (Sandbox Code Playgroud) 我特意将oracle连接到Spring和DBCP.
<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521/ORCL" />
<property name="username" value="PMSYSDB" />
<property name="password" value="********" />
</bean>
Run Code Online (Sandbox Code Playgroud)
但我得到: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (IO Error: The Network Adapter could not establish the connection)
我可以通过SQLDeveloper与这个属性连接:
Hostname: localhost
Port : 1521
SID : ORCL
username: PMSYSDB
password:
Run Code Online (Sandbox Code Playgroud)
所以我的数据库启动并运行...防火墙已关闭...数据库和tomcat在同一台机器上...
认为这不重要,但我使用Spring Security的数据源:
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select username, password, enabled
from users where username=?"
authorities-by-username-query="
select u.username, ur.authority from users u, user_roles …
Run Code Online (Sandbox Code Playgroud) 我尝试运行RichFaces4应用程序,但组件不呈现.例如,当我尝试这个演示:演示我得到这样的东西:
Here is an example of default tab panel with 3 tabs.
j_id1475365623_57f04a9f j_id1475365623_57f04a9f j_id1475365623_57f04a9f
j_id1475365623_57f04a75 j_id1475365623_57f04a75 j_id1475365623_57f04a75
j_id1475365623_57f04a6b j_id1475365623_57f04a6b j_id1475365623_57f04a6b
«
?
»
Here is tab #1
Here is an example of tab panel switched in "ajax" style. Second tab is disabled.
j_id1475365623_57f04a27 j_id1475365623_57f04a27 j_id1475365623_57f04a27
j_id1475365623_57f04a1d j_id1475365623_57f04a1d j_id1475365623_57f04a1d
j_id1475365623_57f04bf3 j_id1475365623_57f04bf3 j_id1475365623_57f04bf3
«
?
»
Here is tab #1
Here is an example of tab panel switched completely on client.
j_id1475365623_57f04bcf j_id1475365623_57f04bcf j_id1475365623_57f04bcf
j_id1475365623_57f04ba5 j_id1475365623_57f04ba5 j_id1475365623_57f04ba5
j_id1475365623_57f04b9b j_id1475365623_57f04b9b …
Run Code Online (Sandbox Code Playgroud) 在JSF的自定义转换器和验证器中,您可以说:
FacesMessage message = new FacesMessage(
FacesMessage.SEVERITY_ERROR, "Invalid length!",
"Length = 8");
throw new ConverterException(message);
Run Code Online (Sandbox Code Playgroud)
并且ti将消息发送到从转换器或验证器确定的某个h:消息组件.有没有办法在常规bean方法中执行类似的操作(如果是这样,如何确定将呈现消息的h:message组件)或更好的方法是在自定义验证器中执行所有验证工作并离开业务没有检查bean方法的逻辑.
我在Spring MVC中处理css文件时遇到问题.css文件的位置和映射有问题.
如果css文件在:
-src
-main
+java
+resources
-webapp
-css
style.css
+WEB-INF
Run Code Online (Sandbox Code Playgroud)
(Maven项目)
我用:
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:annotation-driven/>
Run Code Online (Sandbox Code Playgroud)
in dispatcher-servlet.xml
和access访问它jsp
:
<head>
<title>Insert title here</title>
<link href="/css/style.css" rel="stylesheet" type="text/css">
</head>
Run Code Online (Sandbox Code Playgroud) 根据该文档春天引导注册src/main/resources/static
,src/main/resources/public
,src/main/resources/resources
,等静态资源的位置.
我有
src/main/resources
-static
-js
-stomp.js
Run Code Online (Sandbox Code Playgroud)
并在html(放置在模板文件夹中):
<script type="text/javascript" th:src="@{/js/stomp.js}"></script>
Run Code Online (Sandbox Code Playgroud)
但我得到404的脚本(GET http://localhost:8080/js/stomp.js 404 (Not Found)
).我做错了什么?
我也试过了
<script type="text/javascript" src="../static/js/stomp.js"></script>
Run Code Online (Sandbox Code Playgroud)
和
<script type="text/javascript" src="/js/stomp.js"></script>
Run Code Online (Sandbox Code Playgroud)
结果相同.
我的mvc配置(只有一个视图控制器):
@EnableWebMvc
@ComponentScan(basePackages = {"controller"})
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/sock").setViewName("/index");
}
}
Run Code Online (Sandbox Code Playgroud)
我得到了
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在POM中.
我有多个项目的解决方案(maven父pom和几个子maven项目)。有些项目只是一个maven项目,它使用xjc-schema maven插件从wsdl或xsd生成类。该插件在target / generated-sources文件夹中生成类。现在,解决方案中的其他项目必须使用生成的类,但是eclipse无法识别生成的类。
Intellij Idea对此没有问题,它可以识别生成的类,但是我想使用Eclipse。
我使用Eclipse Neon和基于Neon的Spring Tool Suite进行了尝试。
我尝试刷新,重新启动等,但均未成功。还尝试将带有生成类的项目添加到必须使用这些类的项目的Java Build Path-> Projects中。
java ×8
spring ×4
jdbc ×2
jsf ×2
maven ×2
oracle ×2
spring-mvc ×2
css ×1
eclipse ×1
ejb ×1
hibernate ×1
inheritance ×1
java-ee ×1
javascript ×1
jsp ×1
mapping ×1
message ×1
ora-00942 ×1
richfaces ×1
servlets ×1
singleton ×1
spring-jdbc ×1
static ×1
validation ×1