如何从上一页中检索TextArea值在JSP中?

时间:2013-04-23 09:47:57

标签: java html 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来自不同的数据类型。

3 个答案:

答案 0 :(得分:0)

当ID为description时,您为什么要尝试将值检索为descriptionHidden? 尝试

String description = ParamUtil.get(actionRequest, "description", StringPool.BLANK);

答案 1 :(得分:0)

使用:textarea name="description"

答案 2 :(得分:0)

在view.jsp中,您应该将description元素更改为:

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);
相关问题