我目前正在开发使用nodejs,expressjs,neo4j,d3.js进行可视化的实用程序,但是我陷入了特定的用例中。即搜索功能,我正在做的是使用发布请求通过表单从用户那里获取搜索参数。然后将参数传递给另一个get请求,在此我使用该参数在neo4j中执行查询,并且该get请求用于获取数据以在d3.js中进行可视化。但是我无法将参数从一个(发布)请求传递到另一个(获取)请求的问题。请让我知道如何实现此目标,或者还有其他更好的方法可以使用
表单代码:
import java.util.Scanner;
public class DA_2_searching {
private String name, phone_number;
private static DA_2_searching[] allPersons;
private static Scanner s = new Scanner(System.in);
public DA_2_searching() {
System.out.println("Enter the Details: ");
System.out.print("Name: ");
this.name = s.next();
System.out.print("Phone-Number: ");
this.phone_number = s.next();
System.out.println("\nNext: ");
}
public static void search() {
System.out.println("Type a word to search for: ");
String toSearch = s.next();
for(DA_2_searching person : allPersons) {
if(person.name.contains(toSearch)) { //contains is better for searching.
System.out.println("Result: " + person.name + " | " + person.phone_number);
}
}
System.out.println("\n");
if(!toSearch.equals("exit")) {
search();
}
}
public static void main(String args[]) {
System.out.print("Amount of Entries: ");
int n = s.nextInt();
System.out.println("");
allPersons = new DA_2_searching[n];
//Creating Persons
for(int i = 0; i < n; i++) {
allPersons[i] = new DA_2_searching();
}
//initializing search
search();
}
发布请求:
<form method="post" action="/api/xyz">
<h4> Name</h4>
<div class="item">
<input id="name" type="text" name="searchname" required/>
</div>
<div class="btn-block">
<button type="submit" href="/">Search</button>
</div>
</form>
获取请求:
router.post('/xyz',(req,res,next)=>{
proteinname = req.body.proteinname
console.log(proteinname)
res.render('searchresult')
})