我必须在服务器启动时而不是在第一个请求上执行struts2操作.
所以我有一个接受泛型类型参数的类,如果type参数是给定类型的子类,则会进行一些特殊处理.
IEnumerable<T> models = ...
// Special handling of MySpecialModel
if (filterString != null && typeof(MySpecialModel).IsAssignableFrom(typeof(T)))
{
var filters = filterString.Split(...);
models =
from m in models.Cast<MySpecialModel>()
where (from t in m.Tags
from f in filters
where t.IndexOf(f, StringComparison.CurrentCultureIgnoreCase) >= 0
select t)
.Any()
select (T)m;
}
Run Code Online (Sandbox Code Playgroud)
但是我在最后一行得到例外
Cannot convert type 'MySpecialModel' to 'T'
Run Code Online (Sandbox Code Playgroud)
如果我更改代码as而不是强制转换,我会收到此错误.
The type parameter 'T' cannot be used with the 'as' operator because it does not have a class type constraint nor a 'class' …Run Code Online (Sandbox Code Playgroud) 1l为long,1f为float,1d为double,字节怎么样?
long l = 1l;
float f = 1f;
double d = 1d;
// byte b = 1?;
Run Code Online (Sandbox Code Playgroud)
什么相当于byte?它存在吗?
我经常需要比较两个文件,而忽略这些文件中的某些更改.我不想忽略整条线,只是它们的一部分.最常见的情况是线上的时间戳,但我还需要忽略其他几十种模式.
文件1:
[2012-01-02] Some random text foo
[2012-01-02] More output here
Run Code Online (Sandbox Code Playgroud)
文件2:
[1999-01-01] Some random text bar
[1999-01-01] More output here
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我想看到第1行的差异,但不是第2行.
使用diff的-I选项不起作用,因为它忽略整行.理想输出:
--- file1 2013-04-05 13:39:46.000000000 -0500
+++ file2 2013-04-05 13:39:56.000000000 -0500
@@ -1,2 +1,2 @@
-[2012-01-02] Some random text foo
+[1999-01-01] Some random text bar
[2012-01-02] More output here
Run Code Online (Sandbox Code Playgroud)
我可以用sed预处理这些文件:
sed -e's/^\[....-..-..\]//' < file1 > file1.tmp
sed -e's/^\[....-..-..\]//' < file2 > file2.tmp
diff -u file1.tmp file2.tmp
Run Code Online (Sandbox Code Playgroud)
但后来我需要将这些临时文件放在某处,并记得事后清理它们.此外,我的diff输出不再引用原始文件名,也不再发出原始行.
是否有广泛可用的差异变体或类似工具,可以作为单个命令执行此操作?
我在Netbeans中建立了一个项目,创建了一个脚本,用javadb建立了一个新的数据库.我可以通过gui连接到它 - 显示表内容等,但当我运行一个应用程序时:
EntityManager em = Persistence.createEntityManagerFactory("lab5PU").createEntityManager();
Run Code Online (Sandbox Code Playgroud)
我得到这个很长的例外:
[EL Info]: 2013-04-05 21:40:45.554--ServerSession(1198260109)--EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504
[EL Severe]: 2013-04-05 21:40:45.574--ServerSession(1198260109)--Local Exception Stack:
Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [org.apache.derby.jdbc.ClientDriver] not found.
Exception Description: Configuration error. Class [org.apache.derby.jdbc.ClientDriver] not found.
at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:82)
Run Code Online (Sandbox Code Playgroud)
我可以在服务的驱动程序部分看到javadb驱动程序,所以我不知道错误是什么.
编辑:persistance.xml按要求:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="lab5PU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>lab5.Colleagues</class>
<properties> …Run Code Online (Sandbox Code Playgroud) 我使用了Struts 2框架,并创建了一个具有登录页面的Web应用程序.我有三个不同的Action类,名称Action1,Action2和Action3,以及通过在Action类中运行一些业务逻辑呈现的JSP页面的不同视图.
现在,我想检查用户是否在Action类执行处理之前已登录.所以,我在下面创建了一个拦截器工作正常.
public String intercept(ActionInvocation invocation) throws Exception
{
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
HttpSession session = request.getSession();
if(session.isNew())
{
response.sendRedirect("Login.action");
}
System.out.println("Interceptor Fired");
String result = invocation.invoke();
return result;
}
Run Code Online (Sandbox Code Playgroud)
我想要的struts.xml不是为下面的所有动作添加拦截器
<interceptor-ref name="newStack"/>
Run Code Online (Sandbox Code Playgroud)
我的struts.xml档案有
<package name="default" extends="struts-default">
<interceptors>
<interceptor name="printMsgInterceptor" class="LoginInterceptor"></interceptor>
<interceptor-stack name="newStack">
<interceptor-ref name="printMsgInterceptor"/>
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<action name="actone" class="Action1">
<result name="success">/success.jsp</result>
<interceptor-ref name="newStack"/>
</action>
<action …Run Code Online (Sandbox Code Playgroud) 我正在阅读JVM规范,试图找出如何正确处理监视器.他们在相关部分中给出的示例如下所示:
0 aload_1 // Push f
1 dup // Duplicate it on the stack
2 astore_2 // Store duplicate in local variable 2
3 monitorenter // Enter the monitor associated with f
4 aload_0 // Holding the monitor, pass this and...
5 invokevirtual #5 // ...call Example.doSomething()V
8 aload_2 // Push local variable 2 (f)
9 monitorexit // Exit the monitor associated with f
10 goto 18 // Complete the method normally
13 astore_3 // In case of …Run Code Online (Sandbox Code Playgroud) 我在我的django项目中有一个autocomplete_light的工作实现,从一个下拉列表中的cities_light中提取值,这正确地将外键保存到表单提交中的db中的字段.当我重新访问表单时,我希望自动完成文本字段默认为保存的值,理想情况下使用纯文本中的值并使用"X"按钮(就像已经内置的那样).目前,我看到占位符文本和空白文本字段.当我重新访问表单时,表单中的其他已保存值(此处省略)正确默认.我需要在此处添加什么来触发窗口小部件以显示保存的值?这是我的代码:
forms.py
class UserProfileForm(autocomplete_light.GenericModelForm):
location = autocomplete_light.GenericModelChoiceField(
widget=autocomplete_light.ChoiceWidget(
autocomplete='AutocompleteItems',
autocomplete_js_attributes={'placeholder':'City, State, Country',
'minimum_characters': 3})
)
class Meta:
model = UserProfile
fields = ['location']
Run Code Online (Sandbox Code Playgroud)
models.py
class UserProfile(models.Model):
user = models.ForeignKey(
User,
unique=True
)
location = models.ForeignKey(
City,
blank=True,
null=True
)
Run Code Online (Sandbox Code Playgroud)
autocomplete_light_registry.py
class AutocompleteItems(autocomplete_light.AutocompleteGenericBase):
choices = (
City.objects.all(),
)
search_fields = (
('search_names',),
)
autocomplete_light.register(AutocompleteItems)
Run Code Online (Sandbox Code Playgroud) 我遇到了用于Java的Sphinx语音识别库的问题.我用它来获取输入并处理它.我第一次得到输入,它的工作原理.第二次,它在我有机会谈话之前立即回答.在那之后,它继续回答自己.我尝试在每次输入之前分配并在每次输入后解除分配,但这似乎不起作用.我能做什么?
代码:
这是处理输入的方法:
public void getInput() {
if (using) return;
using = true;
if (!allocated) {
JTalk.speak("Please hold.");
recognizer.allocate();
allocated = true;
}
JTalk.speak("Speak now.");
Result result = recognizer.recognize();
if (result != null) {
String resultText = result.getBestFinalResultNoFiller();
JDispatcher.getInstance().matchInput(resultText);
}
else {
JTalk.speak("Try again.");
}
using = false;
}
Run Code Online (Sandbox Code Playgroud)
你需要知道的:
MouseListenerfor a TrayIcon.speak(String)运行say <text>从Runtime.matchInput(String) 迭代数组中所有已注册的侦听器并测试匹配.更新2:
根据Nikolay Shmyrev的回答,我尝试在构造函数中分配麦克风,并在适当的时间启动,然后停止麦克风getInput().
这是SphinxBridge类:
public class SphinxBridge {
private ConfigurationManager cm; …Run Code Online (Sandbox Code Playgroud) 我要在几小时内区分当前日期和存储在数据库中的日期.在PostgreSQL中,我可以使用以下查询来完成它:
SELECT storage_time, extract(epoch from (localtimestamp - storage_time))/3600 as diff_hour FROM some_table;
Run Code Online (Sandbox Code Playgroud)
这给了我以小时为单位的日期差异:
storage_time | diff_hour
-------------------------+-------------------
2014-02-03 19:37:39.481 | 44.4788805811111
2014-02-03 19:40:28.201 | 44.4320139144444
2014-01-29 18:25:12.828 | 165.686284192222
2014-02-03 19:25:56.861 | 44.6740528033333
2014-02-05 15:53:38.178 | 0.212575858888889
2014-01-30 15:53:38.61 | 144.212455858889
Run Code Online (Sandbox Code Playgroud)
现在,我面临着将其移植到Hibernate查询语言的困难.我尝试了很多变化,但我无法从日期差异中获得时代.这肯定不起作用:
"FROM SomeEntity " +
"WHERE someAttribute = :attr " +
"AND epoch(localtimestamp - deviceInfo.storageTime) / 3600 > :threshold_hour";
Run Code Online (Sandbox Code Playgroud)
当我运行此命令时,我得到以下异常:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273) …Run Code Online (Sandbox Code Playgroud) java ×7
casting ×2
struts2 ×2
.net ×1
action ×1
byte ×1
bytecode ×1
c# ×1
compare ×1
database ×1
date ×1
diff ×1
django ×1
forms ×1
generics ×1
hibernate ×1
hql ×1
java-ee ×1
javadb ×1
jquery ×1
linq ×1
netbeans ×1
postgresql ×1
python ×1
regex ×1
sphinx4 ×1
startup ×1
struts ×1
synchronized ×1
tomcat ×1
unix ×1