简体   繁体   中英

How to Retrieve TextArea value from previous page In JSP?

I want to retrieve textarea data from this view.jsp

<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> 

To here 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);
     }  

I could do it for gender , email and name. Apparently textArea is from a different datatype.

When the id is description , why are you trying to retrieve the value back as descriptionHidden ? try

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

使用: textarea name="description"

In your view.jsp you should change the description-element to this:

Description: <textarea name="description"> Enter text here...</textarea>

Also in your view.jsp you should remove this line:

String description = $("description").val();

You're using some jQuery here but it is in the middle of your html for some reason. Also if you want to select an element using its id-attribute you should use the selector $("#description").

In your TestPackage.java change the line where you set your description to this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM