我试图从一个小型facelet应用程序将一些值保留到MySql数据库,但不断收到此错误.我有一个JPS页面和一个servlet这个相同的应用程序,它与大致相同的逻辑工作得很好,这是我第一次尝试使用facelets所以它可能只是一些愚蠢但我会帮助你.
谢谢
错误
javax.faces.el.EvaluationException: javax.persistence.TransactionRequiredException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.persistence.TransactionRequiredException
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTxRequiredCheck(EntityManagerWrapper.java:163)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTransactionScopedTxCheck(EntityManagerWrapper.java:145)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:263) …Run Code Online (Sandbox Code Playgroud) 如何修改此代码以生成3个列表,每个列表包含5个元素,而不是现在; 3个列表包含5/10/15个元素?
import random
y = []
def autoSolve():
for i in range(5):
z = random.randrange(1, 10)
y.append(z)
print(y, end="")
for i in range(3):
print("number", i + 1,)
autoSolve()
print()
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用map函数转换列表的值,但我得到一个奇怪的结果.
s = input("input some numbers: ")
i = map(int, s.split())
print(i)
Run Code Online (Sandbox Code Playgroud)
得到:
input some numbers: 4 58 6
<map object at 0x00000000031AE7B8>
Run Code Online (Sandbox Code Playgroud)
为什么它不会返回['4','58','6']?
我刚刚在我的笔记本电脑上安装了ubuntu 13.10 x64,我继续安装了Intellij Idea12,它在我的32位系统上完美运行,两台机器都有来自oracle的java 1.7.0_45.当我从终端上运行x64上的Idea.sh时,我得到:
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
Failed to clear URL cache
Run Code Online (Sandbox Code Playgroud)
如果我运行它作为sudo我得到相同的输出,但它启动,所以我真的想知道问题是什么,我已经使用Intellij-Idea启动的缓存(Files-> Invalidate缓存)无效,并且还删除了手动缓存所有缓存但问题仍然存在.
提前致谢.
我的问题是关于为什么一段代码工作而另外两段没有,以及我如何获得无效的代码.
有效的代码:
mysql_select_db("webuser1", $con);
mysql_query("INSERT INTO users (column 1, column2) VALUES ('value1', 'value2')");
mysql_close($con);
Run Code Online (Sandbox Code Playgroud)
代码no1没有($ var1包含'value1'等):
mysql_select_db("webuser1", $con);
mysql_query("INSERT INTO users (column 1, column2) VALUES ($var1, $var2)");
mysql_close($con);
Run Code Online (Sandbox Code Playgroud)
并且代码no2不起作用($ _POST ['value1']包含'value1'等):
mysql_select_db("webuser1", $con);
mysql_query("INSERT INTO users (column 1, column2) VALUES ($_POST['value1'], $_POST['value2'])");
mysql_close($con);
Run Code Online (Sandbox Code Playgroud)
我不应该能够在mysql中插入$ var或$ _POST吗?我希望你没有发现这个Q傻,但我一直在寻找解决方案,但我还没有理解它们.谢谢
在print("you dont have that many cards!")我希望while循环重新开始
print("how many cards in heap no:", n, end="")
Run Code Online (Sandbox Code Playgroud)
而不是打破.如何才能做到这一点?
y = []
def cardHeaps():
global cards
n = 1
while int(cards) > 0:
print("how many cards in heap no:", n, end="")
x = int(input("? "))
cards = int(cards)
if x > cards:
print("you dont have that many cards!")
break
y.append(x)
cards -= int(x)
print(cards, " cards left")
n += 1
if cards <= 0:
print("out of cards!")
break
Run Code Online (Sandbox Code Playgroud) 我有一个只能包含整数的列表,如何继续控制列表的每个元素,如果它不是int,则返回一条消息?
我可以用某种方式使用isdigit()吗?
谢谢
我很清楚这是一个noob问题,但我似乎无法找到解决方案,我对编程很新,但渴望学习.我正在浏览python中的第一个google clases,这是我得到的错误.
def both_ends(s):
print s[0:2], s[3:5]
return
x = input('...: ')
both_ends(x)
sergei@sergei-MS-7253:~/Desktop/p2$ python test2.py
...: haloj
Traceback (most recent call last):
File "test2.py", line 10, in <module>
x = input('...: ')
File "<string>", line 1, in <module>
NameError: name 'haloj' is not defined
Run Code Online (Sandbox Code Playgroud)
请解释一下问题所在.
谢谢
我从input()得到一个字符串,它由用空格分隔的数字组成(1 5 6 3).首先,我试图检查输入只包含带有isdigit()函数的数字,但由于空格我无法使其工作.然后我使用split()函数将字符串转换为列表.
我需要的是实现从输入列表和使舒尔只由数字组成,其他人发送消息,并要求新的输入.是不是可以在isdigit()中添加一个参数来为空格做一个例子?
谢谢