[英]How to Retrieve TextArea value from previous page In JSP?
我想从此view.jsp检索textarea数据
<form action="${addStudentUrl}" method="post">
Name:<input name="name" type="text" />
<br>
<br>
Email:<input name="email" type="text" />
<br>
<br>
Gender:
<br>
<input type="radio" name="gender" value="1">Male<br>
<input type="radio" name="gender" value="2">Female
<br>
Description: <textarea id="description"> Enter text here...</textarea>
String description = $("description").val();
<input type="submit" value="Add"/>
</form>
到这里TestPackage.java
@ProcessAction(name="addStudent")
public void addStudent(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException, PortalException, com.liferay.portal.kernel.exception.SystemException
{
String name=ParamUtil.get(actionRequest, "name", StringPool.BLANK);
int gender=Integer.parseInt(ParamUtil.get(actionRequest, "gender", StringPool.BLANK));
String email=ParamUtil.get(actionRequest, "email", StringPool.BLANK);
String description = ParamUtil.get(actionRequest, "descriptionHidden", StringPool.BLANK);
StudentLocalServiceUtil.addStudent(name, gender, email, description);
}
我可以输入性别,电子邮件和姓名。 显然textArea来自不同的数据类型。
当id为description
,为什么要尝试将值作为descriptionHidden
取回? 尝试
String description = ParamUtil.get(actionRequest, "description", StringPool.BLANK);
使用: textarea name="description"
在您的view.jsp中,您应该将description-element更改为:
Description: <textarea name="description"> Enter text here...</textarea>
同样在view.jsp中,您应该删除以下行:
String description = $("description").val();
您在此处使用了一些jQuery,但出于某种原因它却位于html的中间。 另外,如果要使用其id属性选择元素,则应使用选择器$(“#description”)。
在您的TestPackage.java中,更改将描述设置为此的行:
String description = ParamUtil.get(actionRequest, "description", StringPool.BLANK);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.