Java 从jsp获取字符串以创建另一个jsp

Java 从jsp获取字符串以创建另一个jsp,java,spring,jsp,textarea,Java,Spring,Jsp,Textarea,是否有一种方法可以从文本区域(例如,从jsp)获取字符串,然后,当我单击按钮时,将该字符串发送给控制器,控制器在方法中使用该字符串,该方法反过来基于该字符串以列表形式返回查询,然后显示另一个带有此列表的jsp 到目前为止,我已经试过了: <form:form method="post" action="UserContracts" commandName="somedata" > <table> <tr> <td><h3 style=

是否有一种方法可以从文本区域(例如,从jsp)获取字符串,然后,当我单击按钮时,将该字符串发送给控制器,控制器在方法中使用该字符串,该方法反过来基于该字符串以列表形式返回查询,然后显示另一个带有此列表的jsp

到目前为止,我已经试过了:

<form:form method="post" action="UserContracts" commandName="somedata" >
<table>
<tr>
    <td><h3 style="color:#0080ff;">Enter CNP :</h3></td>
    <td><form:input path="cnp" /></td>
<tr>
    <td colspan = "2"><input name="cnp" type="text"/></td>
<tr>
    <td colspan="2">
        <br>
        <input type="submit" value="Find" class="button" />
    </td>
</tr>

输入CNP:

@RequestMapping(“/uc”)
公共字符串userContract(@ModelAttribute(“somedata”)字符串cnp,HttpServletRequest请求,模型模型)
{   
List ContractList=新建ArrayList();
合同清单=cl.getContractsOfUser(cnp);
model.addAttribute(“ContractList”,ContractList);
System.out.println(“在uc中”);
返回“用户合同”;
}

action属性指示将处理该表单的后端端点。在您的例子中,您已经放置了“UserContracts”,但是您正在将方法userContract映射到“/uc”。这些必须匹配,以便请求命中该控制器,或者更改表单操作或端点url,使它们相同。

这最终奏效了

@RequestMapping(value=“/uc”)
公共字符串userContracts(@RequestParam(“nr”)字符串nr,模型)
{
List ContractList=新建ArrayList();
合同清单=cl.getContractsOfUser(nr);
model.addAttribute(“ContractList”,ContractList);
System.out.println(“在uc中”);
返回“用户合同”;
}

输入CNP:



Hi。我已经做了更改,但当我按下“查找”按钮时,什么也没有发生。有什么想法吗?1-你试过使用正则形式吗?这代替了:do:2-你记得关闭感谢你的回复吗。自从发帖以来,我已经解决了这个问题。
@RequestMapping("/uc")
public String userContract(@ModelAttribute("somedata") String cnp,HttpServletRequest request, Model model) 
{   

    List<Contract> ContractList = new ArrayList<Contract>();

    ContractList = cl.getContractsOfUser(cnp);

    model.addAttribute("ContractList", ContractList);
    System.out.println("In uc");
    return "UserContracts";
}
@RequestMapping(value = "/uc")
public String userContracts(@RequestParam("nr") String nr, Model model)
{
  List<Contract> ContractList = new ArrayList<Contract>();

  ContractList = cl.getContractsOfUser(nr);
  model.addAttribute("ContractList", ContractList);
    System.out.println("In uc");
    return "UserContracts";
}
<table>
<form action="http://localhost:8080/VR/uc.html">
<tr><td>
<h3 style="color:#0080ff;">Enter CNP :</h3>
<tr><td>
<input name="nr" type="text">
<tr><td align="center">
<br>
<br>
<input type="submit" value="Find">
</form>
</table>