String a = "Hello\u200e";
String b = "Hello\u200f";
System.out.println("a = '" + a + "' and b = '" + b + "' are length "
+ a.length() + " and " + b.length()
+ ", equals() is " + a.equals(b));
Run Code Online (Sandbox Code Playgroud)
上面代码段中的代码生成以下输出.
a ='Hello'和b ='Hello'的长度为6和6,equals()为false
虽然控制台上显示的值a和值b都是Hello?,但a.equals(b)返回false.怎么样?
在GlassFish(3.1.2.2b5)上运行的Java EE 6应用程序中,假设您有一个ConfigurationService,它读取一些属性文件并相应地分发属性值:
@Local
public interface ConfigurationService { ... }
Run Code Online (Sandbox Code Playgroud)
@Singleton
public class ConfigurationServiceImpl implements ConfigurationService { ... }
Run Code Online (Sandbox Code Playgroud)
还有一个Eclipselink SessionCustomizer,因为应用程序中的一个持久性单元(Oracle数据库)的模式名称需要以编程方式设置,即可以从之前提到的属性文件进行配置.的SessionCustomizer是在配置persistence.xml和实施包含对一个参考ConfigurationService:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"...
<persistence-unit name="myPU" transaction-type="JTA">
<property name="eclipselink.session.customizer" value="MySessionCustomizer"/>
...
Run Code Online (Sandbox Code Playgroud)
public class MySessionCustomizer implements SessionCustomizer {
@EJB
private ConfigurationService configurationService;
@Override
public void customize(Session session) {
session.getLogin().setTableQualifier(configurationService.getSchemaName());
...
Run Code Online (Sandbox Code Playgroud)
是否有可能以ConfigurationService这种方式注入,以便在SessionCustomizer实例化时可用?上述操作失败,因为ConfigurationService实例仍然为空,即注入尚未发生.此观察对应于服务器的日志条目.似乎依赖注入机制总是在持久性单元 - 因此SessionCustomizer- 被实例化之后开始.我搞砸周围的各种注释(@Startup,@DependsOn(...),...),但无济于事.我的结论是正确的还是有另一种方法让EJB更早实例化并注入?
如何转换
org.apache.poi.hssf.usermodel.HSSFWorkbook
Run Code Online (Sandbox Code Playgroud)
至
org.apache.poi.xssf.usermodel.XSSFWorkbook
Run Code Online (Sandbox Code Playgroud)
在Apache POI?
环境 :
根据我几天前发布的问题,我意识到这SimpleFormController不适合处理Ajax请求.因此,我正在将我的应用程序迁移到带注释的控制器.
我正在尝试java.util.List使用Spring MVC 3.0.2和Hibernate通过Ajax使用Jackson 1.9.8(其下载页面)从Oracle数据库返回,但我还没有在任何技术中使用JSON.我已经阅读了一些教程/文章但我无法理解如何返回这样复杂的数据结构并在Spring中使用JSON解析它们.我首先尝试学习类似JSON的概念.
基本上我正在尝试的是当从国家选择框中选择国家时,应该通过Ajax从数据库填充与该国家相对应的州.我不知道如何返回java.util.ListAjax响应,如何解析它并在Java代码中再次使用它.我只达到以下水平.
JS代码.
function getStates(countryId)
{
$.ajax({
datatype:"json",
type: "POST",
url: "/wagafashion/ajax/TempAjax.htm",
data: "countryId=" + countryId,
success: function(response)
{
$('#msg').html(response);
$('#stateList').val('');
},
error: function(e)
{
alert('Error: ' + e);
}
});
}
Run Code Online (Sandbox Code Playgroud)
Spring控制器类中的方法,当onchange在国家/地区选择框的事件上发出Ajax请求时调用该方法.
@RequestMapping(method=RequestMethod.POST, value="ajax/TempAjax")
public @ResponseBody List<StateTable> getStateList(@ModelAttribute("tempBean") TempBean tempBean, BindingResult error, Map model, HttpServletRequest request, HttpServletResponse response)
{
Session session=NewHibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<StateTable>list=session.createQuery("from StateTable where country.countryId=:countryId order by stateId").setParameter("countryId", …Run Code Online (Sandbox Code Playgroud) 我需要根据ids提供的数组(如SELECT ... FROM table_name WHERE id IN()查询)从Oracle数据库中获取所选行.
在我试图这样做时,我试图org.hibernate.setParameterList(String name, Object[] values)在我的DAO中使用该方法如下.
@Service
@Transactional(readOnly = true, propagation=Propagation.REQUIRES_NEW)
public final class ProductImageDAO implements ProductImageService {
@SuppressWarnings("unchecked")
public List<Object[]> getFileName(String[] list) {
return sessionFactory
.getCurrentSession()
.createQuery("SELECT prodImageId, prodImage FROM ProductImage WHERE prodImageId=:list")
.setParameterList("list", list).list();
}
}
Run Code Online (Sandbox Code Playgroud)
String[]给定方法中的类型参数由相应的Spring控制器类提供.
它会导致抛出以下异常.
org.hibernate.hql.ast.QuerySyntaxException:意外的令牌:,在第1行第78列附近[从model.ProductImage中选择prodImageId,prodImage,其中prodImageId =:id0_,:id1_,:id2_,:id3_,:id4_,:id5_]
根据ids使用Hibernate的列表检索所选行的方法是什么?
我用,
其中,我使用内置安全令牌来防范CSRF攻击.
<s:form namespace="/admin_side"
action="Category"
enctype="multipart/form-data"
method="POST"
validate="true"
id="dataForm"
name="dataForm">
<s:hidden name="%{#attr._csrf.parameterName}"
value="%{#attr._csrf.token}"/>
</s:form>
Run Code Online (Sandbox Code Playgroud)
它是其中CSRF令牌是不可用的,除非春季安全多部分请求MultipartFilter连同MultipartResolver被适当地配置成使得所述多请求由弹簧处理.
MultipartFilterin web.xml配置如下.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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/web-app_3_0.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<filter>
<filter-name>MultipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>MultipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>AdminLoginNocacheFilter</filter-name>
<filter-class>filter.AdminLoginNocacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AdminLoginNocacheFilter</filter-name>
<url-pattern>/admin_login/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>NoCacheFilter</filter-name>
<filter-class>filter.NoCacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>NoCacheFilter</filter-name>
<url-pattern>/admin_side/*</url-pattern> …Run Code Online (Sandbox Code Playgroud) 我只需要使用JPA标准执行以下MySQL查询(state_table根据给定的国家名称(in country)获取状态列表(from )).
SELECT state_id,
state_name,
country_id
FROM state_table
WHERE country_id IN(SELECT country_id
FROM country
WHERE country_name = ?)
Run Code Online (Sandbox Code Playgroud)
我编写了以下JPA条件查询.
CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder();
CriteriaQuery<StateTable>criteriaQuery=criteriaBuilder.createQuery(StateTable.class);
Root<StateTable> root = criteriaQuery.from(entityManager.getMetamodel().entity(StateTable.class));
Subquery<Long> subquery = criteriaQuery.subquery(Long.class);
Root<Country> subRoot = subquery.from(Country.class);
subquery.select(subRoot.get(Country_.countryId));
ParameterExpression<String>parameterExpression=criteriaBuilder.parameter(String.class);
subquery.where(criteriaBuilder.equal(subRoot.get(Country_.countryName), parameterExpression));
criteriaQuery.where(criteriaBuilder.in(root.get(StateTable_.country).get(Country_.countryId)).value(subquery));
List<StateTable> list = entityManager.createQuery(criteriaQuery).setParameter(parameterExpression, "India").getResultList();
Run Code Online (Sandbox Code Playgroud)
此条件查询不必要地在生成的SQL查询中生成冗余连接,如下所示.
SELECT t1.state_id,
t1.state_name,
t1.country_id
FROM projectdb.country t0,
projectdb.state_table t1
WHERE (t0.country_id IN (SELECT t2.country_id
FROM projectdb.country t2
WHERE (t2.country_name = ? ))
AND (t0.country_id = t1.country_id ))
Run Code Online (Sandbox Code Playgroud)
可以注意到,存在冗余连接AND (t0.country_id = …
为了utf8mb4在MySQL(5.6.11)中使用4字节,我在my.ini文件中设置了以下变量(my.cnf未找到).此文件位于Windows XP上名为Application Data(C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6)的隐藏文件夹中.它在安装目录下不可用.
[client]
port=3306
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
init-connect='SET NAMES utf8mb4'
collation_server=utf8mb4_unicode_ci
character_set_server=utf8mb4
Run Code Online (Sandbox Code Playgroud)
然后发出以下命令,
SHOW VARIABLES
WHERE Variable_name
LIKE 'character\_set\_%'
OR Variable_name LIKE 'collation%';
Run Code Online (Sandbox Code Playgroud)
仍显示以下列表.

从图片本身可以看出,几个变量仍然使用3字节utf8.
在执行此操作之前,已发出以下命令以对数据库本身进行相应的更改.
ALTER DATABASE database_name
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
Run Code Online (Sandbox Code Playgroud)
并且还在所述数据库中的每个表上发出以下命令.
ALTER TABLE table_name
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
Run Code Online (Sandbox Code Playgroud)
然而,为什么有些变量尚未设置为所述字符集以及整理?缺什么?
在执行上面指定的每个任务之后,系统(操作系统)本身重新启动.
我正在使用GlassFish Server 4.1/Java EE 7.在我的web.xml文件中,我提到了以下安全约束.
<security-constraint>
<display-name>UserConstraint</display-name>
<web-resource-collection>
<web-resource-name>Provide a Name</web-resource-name>
<description/>
<url-pattern>/admin_side/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>ROLE_ADMIN</role-name>
</auth-constraint>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)
其他当局也是如此.
由于transport-guarantee设置为CONFIDENTIAL,与指定的URL模式匹配的网页/admin_side/*通过安全通道(HTTPS)运行.
使用WebSockets时如下(JavaScript),
var ws = new WebSocket("ws://localhost:8181/Context/Push");
Run Code Online (Sandbox Code Playgroud)
它无法建立初始握手.浏览器在浏览器控制台上显示以下警告.
[blocked] The page at 'https://localhost:8181/Context/admin_side/Category' was loaded over HTTPS, but ran insecure content from 'ws://localhost:8080/Context/Push': this content should also be loaded over HTTPS.
Uncaught SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from …Run Code Online (Sandbox Code Playgroud) 我已将PrimeFaces从5.1决赛升级到5.2决赛(社区发布).我有一个<p:dataTable>懒惰加载如下(一个最小的例子来重现问题仅用于纯测试目的).
<p:dataTable var="row"
value="#{testManagedBean}"
lazy="true"
editable="true"
rowKey="#{row.fruitId}"
selection="#{testManagedBean.selectedValues}"
rows="50">
<p:column selectionMode="multiple"/>
<p:ajax event="rowEdit" listener="#{testManagedBean.onRowEdit}"/>
<p:column headerText="Id">
<h:outputText value="#{row.fruitId}"/>
</p:column>
<p:column headerText="Fruit Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.fruitName}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{row.fruitName}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Price">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.price}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{row.price}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit">
<p:rowEditor/>
</p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
相应的托管bean:
@Named
@ViewScoped
public class TestManagedBean extends LazyDataModel<Fruit> implements Serializable {
private List<Fruit> selectedValues; // Getter & setter.
private static final long serialVersionUID …Run Code Online (Sandbox Code Playgroud) java ×4
eclipselink ×2
mysql ×2
ajax ×1
apache-poi ×1
criteria-api ×1
csrf ×1
ejb-3.1 ×1
hibernate ×1
hql ×1
html5 ×1
jackson ×1
java-ee ×1
java-ee-6 ×1
java-ee-7 ×1
jpa ×1
jpa-2.0 ×1
jsf ×1
jsf-2.2 ×1
json ×1
mysql-5.6 ×1
openxml ×1
oracle ×1
primefaces ×1
spring ×1
spring-mvc ×1
ssl ×1
struts2 ×1
utf-8 ×1
utf8mb4 ×1
websocket ×1