我最近开始使用Spring MVC框架.我在网上阅读大量教程时取得了很大的进步.
关于我申请的背景 -
我必须使用表单中提供的详细信息对其他服务(已在tomcat上部署)进行REST URL调用.所以我已经使用JSP创建了一个表单,其内容如下图所示 - 我不知道如何通过从表单条目中创建url然后显示该URL的响应来进行REST URL调用下一个屏幕.
所以在上面的表格中,如果我已经写了User Id as 1000012848,并且checkbox is selected (means true) for Debug Flag在Attribute Name I have selected first row(通常我们也可以选择所有三个)Machine Name is localhost,Port Number is 8080然后url应该看起来像这样 -
http://localhost:8080/service/newservice/v1/get/PP.USERID=1000012848,debugflag=true/host.profile.ACCOUNT
Run Code Online (Sandbox Code Playgroud)
因此,在我们将从表单条目中创建的所有URL中,下面的行总是在同一个位置 - 然后在每个表单条目开始附加后
service/newservice/v1/get/
Run Code Online (Sandbox Code Playgroud)
现在在创建了上面的url之后,只要我点击提交,就会调用上面的url,无论从URL获得什么响应,它都会显示在下一个屏幕(result.jsp文件)中我不知道怎么做?以下是我创建的文件.任何人都可以帮助我解决我的问题吗?我需要做什么代码才能解决这个问题?
student.jsp文件(制作表格)
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<res:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="main" />
<title>First Tutorial</title>
</res:head>
<res:body>
<form:form method="POST" action="/_hostnewapp/addStudent">
<table>
<tr>
<td><form:label path="userId">User Id</form:label></td>
<td><form:input path="userId" /></td>
</tr> …Run Code Online (Sandbox Code Playgroud) 我需要插入有两列的数据库 -
ID PrimaryKey String
ACCOUNT String
Run Code Online (Sandbox Code Playgroud)
这意味着每个线程应始终使用唯一ID,我也需要ID在Account列中存储相同的ID .因此,如果ID is 1那么在数据库中它应该存储为
ID Account
1 SomeString+1
2 SomeString+2
3 SomeString+3
....
..
100 SomeString+100
Run Code Online (Sandbox Code Playgroud)
我总是在Account列中将该userID与该String连接起来.
下面是我的多线程代码,它将产生多个线程 - 每个线程将在每次使用时获得一个新的唯一ID AtomicInteger.它会插入ID到ID column还追加一条ID到Account列
但不知何故,在我的下面的程序中,我在该数据库中看到的是 -
ID Account
1 String+2
2 String+1
3 String+3
Run Code Online (Sandbox Code Playgroud)
哪个不对.它应该像这样 -
ID Account
1 String+1
2 String+2
3 String+3
Run Code Online (Sandbox Code Playgroud)
下面是代码
public static void main(String[] args) {
final int noOfThreads = 4;
final int noOfTasks = …Run Code Online (Sandbox Code Playgroud) 我正在开展一个人们要求我的项目generate random String of 3000 bytes.
有可能吗?我很困惑我们如何生成3000字节的随机字符串?
我知道这样的事情 -
SecureRandom srandom = new SecureRandom();
String rand = new BigInteger(176, srandom).toString(32);
Run Code Online (Sandbox Code Playgroud)
但事实并非如此 3000 bytes
有什么方法可以得到随机字符串 3000 bytes
我需要.在C++中拆分字符串..
下面是我的字符串 -
@event.hello.dc1
现在我需要拆就.在上面的字符串,并从中获取@event,然后传递@event到下面的方法-
bool upsert(const char* key);
以下是我从这里阅读后到目前为止的代码-
void splitString() {
string sentence = "@event.hello.dc1";
istringstream iss(sentence);
copy(istream_iterator<string>(iss), istream_iterator<string>(), ostream_iterator<string>(cout, "\n"));
}
Run Code Online (Sandbox Code Playgroud)
但我无法理解如何@event通过拆分.使用上述方法来提取,因为上述方法仅适用于空白...以及如何通过拆分提取该字符串中的所有内容,.如下所述 -
split1 = @event
split2 = hello
split3 = dc1
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助..
我试图解析JSON从Python.JSON如果我在json字符串周围使用单引号,我能够正确解析但是如果我删除那个单引号然后它对我不起作用 -
#!/usr/bin/python
import json
# getting JSON string from a method which gives me like this
# so I need to wrap around this dict with single quote to deserialize the JSON
jsonStr = {"hello":"world"}
j = json.loads(`jsonStr`) #this doesnt work either?
shell_script = j['hello']
print shell_script
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何围绕单引号包装JSON字符串,以便我能够正确地反序列化它?
我得到的错误 -
$ python jsontest.py
Traceback (most recent call last):
File "jsontest.py", line 7, in <module>
j = json.loads('jsonStr')
File "/usr/lib/python2.7/json/__init__.py", line 326, in loads …Run Code Online (Sandbox Code Playgroud) 我有一个JSP页面,其中有一个如下所示的超链接:
<p class='posDash1'>
<input type="hidden" name="export" value="export_csv">
<a href="/admin/" name ="export"><img class="csvFile" src="/images/excel_logo.gif"/> Export.csv</a>
</p>
Run Code Online (Sandbox Code Playgroud)
现在,如果我点击这个超链接,我需要在servlet中调用我的一个方法.所以在href中,我提供了我的servlet名称.一切都运行正常,这意味着每当我点击这个href时,我现在能够调用我的servlet我不知道如何在servlet中识别出这个调用是来自href链接点击.
所以我添加了一个输入隐藏值,我从中想到,我将能够识别出此调用来自href单击链接,但不知何故它不起作用:
public void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception {
Response rr = null;
// but this always come as null
String export = req.getParameter(export);
if(export.equals("export_csv)) {
// do something here
}
// some code
}
Run Code Online (Sandbox Code Playgroud)
并且每次导出变量值都为null时,我无法识别此调用是否来自href链接点击.有没有办法克服这个问题?
我试图从Github存储库导入大部分基于maven的项目,一旦我导入了所有项目,这就是我在控制台上看到的 -
Project build error: 'dependencies.dependency.version' for org.slf4j:slf4j-jcl:jar is missing. pom.xml /testdemo line 23 Maven pom Loading Problem
Project build error: 'dependencies.dependency.version' for org.slf4j:slf4j-api:jar is missing. pom.xml /testdemo line 28 Maven pom Loading Problem
null (org.apache.maven.plugins:maven-resources-plugin:2.5:resources:default-resources:process-resources) pom.xml /testdemo line 3 Maven Build Problem
null (org.apache.maven.plugins:maven-resources-plugin:2.5:testResources:default-testResources:process-test-resources) pom.xml /testdemo line 3 Maven Build Problem
Run Code Online (Sandbox Code Playgroud)
抱怨org.slf4j:slf4j-jcl:jar失踪有一些错误.
我不确定如何解决这个问题?有什么想法吗?
这是我的pom.xml文件中的内容 -
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jcl</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Python脚本发送电子邮件,但以某种方式希望我将其发送到我的邮箱中,而不是该格式。以下是我发送电子邮件的方法-
def send_mail(data):
sender = 'fromuser@host.com'
receivers = ['touser@host.com']
message = """From: fromuser@host.com
To: touser@host.com
Subject: Send mail from python!!
"""
body = 'Some Text\n'
for item in data:
body = body + '{name} - {res}\n'.format(name=item['name'], res=item['res'])
message = message + body
try:
smtpObj = smtplib.SMTP('corp.host.com' )
smtpObj.sendmail(sender, receivers, message)
print "Mail sent"
except smtplib.SMTPException:
print "You can't spam. Mail sending failed!"
Run Code Online (Sandbox Code Playgroud)
这里的数据只有键-值对。
我在Outlook邮箱中收到这样的电子邮件-
在From:我的前景部分中,下面的字符串是正确的,这是错误的-
fromuser@host.com To: touser@host.com Subject: Send mail from python!!
Run Code Online (Sandbox Code Playgroud)
并且To:,Subject:部分即将显示为空,这也是错误的。 …
当我尝试使用请求库中.json()响应对象的方法时,出现错误:
>>> import requests
>>> response = requests.get("http://example.com/myfile.json")
>>> response_json = response.json()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Response' object has no attribute 'json'
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此错误,我该如何解决?
我有这样的html表单,如这个jsfiddle所示.
如果单击PROCESS按钮,它将显示一个有两个单选按钮的表单.它们现在都是垂直的,这意味着女性单选按钮正好在男性单选按钮下方.
我试图让它们在一行 - 意思是Male单选按钮然后在男性旁边,我需要Female单选按钮,一切都是水平的.但不知何故,这对我不起作用.
但w3schools中的相同示例运行良好.
我想使用我目前使用的相同设计.我在上面的jsfiddle中有什么不对吗?