본문 바로가기

WEB_Programming/Struts

Textarea Tag<html:textarea>: 사용법

Textarea Tag<html:textarea>:

html:textarea Tag - textarea 엘리먼트 생성, 이태근느 form태그 내에서만 유용하다.

 

속성 설명 :

name       : input field에 현재값을 렌더링 할때 어떠한 속성과 연관된 빈인지에 대한 속성. 이 값이 지정되지 않은경우 폼 태그에 따른다.

property   : 입력 필드의 이름, value값이 지정되어 있지 않다면 빈 프로퍼티에 상응하는 이름에 대한 값이 지정

readyonly : 입력 필드를 읽기 전용으로 만듬

value       : 초기화될 값 지정


 

Example code
폼 빈 생성 : TextAreaActionForm.java.

 package ActionForm;

import! javax.servlet.http.HttpServletRequest;
import! org.apache.struts.action.ActionErrors;
import! org.apache.struts.action.ActionMapping;
import! org.apache.struts.action.ActionMessage;

public class TextAreaActionForm extends org.apache.struts.action.ActionForm {
   
     private String message;
 
    public String getMessage() {
        return message;
    }
   
    public void setMessage(String string) {
        message = string;
    }
       
    public TextAreaActionForm() {
        super();
  }

}

 

Action Class 생성 : TextAreaAction.java.

 package action;

import! ActionForm.TextAreaActionForm;
import! javax.servlet.http.HttpServletRequest;
import! javax.servlet.http.HttpServletResponse;

import! org.apache.struts.action.Action;
import! org.apache.struts.action.ActionForm;
import! org.apache.struts.action.ActionMapping;
import! org.apache.struts.action.ActionForward;

public class TextAreaAction extends Action {
       
    private final static String SUCCESS = "success";
   
    public ActionForward execute(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        if(form!=null){
            TextAreaActionForm texAreaActionForm=(TextAreaActionForm)form;
            String message=texAreaActionForm.getMessage();
            System.out.println("raj"+message);
        }
       
        return mapping.findForward(SUCCESS);
       
    }
}

 

struts-config.xml 에 폼빈 설정 
Add the following entry in the struts-config.xml file for defining the form bean :

 

 <form-bean name="TextAreaActionForm" type="ActionForm.TextAreaActionForm"/>

 

struts-config.xml 액션 매핑 설정 : 
Here, Action mapping helps to select FormBean and Action  etc, from the  class for specific requests.

 <%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <th align="right"><font color="#33FF99"
>HTML:TEXTAREA EXAMPLE</font>
    </th><br/>>

</head>
<body bgcolor="#999933">

<font color="#33FF99">Please Enter the Message------</font><br/>

<h4><font color="#33FF99">Message </font><h4><br/>
<html:form action="TextAreaAction">
<table border="2">

<td align="left">
    <html:textarea property="message"/><br/>
</td>
</tr>
<tr>
    <td align="left">
        <html:submit/>
    </td>
    </td>
</tr>
</table>
</html:form>


</body>
</html>


HtmlTextAreaOutPut.jsp 생성:

Add the following line in the index.jsp to call the form.

 <a href="HtmlTextAreaTag.jsp">HtmlTextAreaTagDemo</a><br/>

Building and Testing the Example  :
Build and deploy and Test  the application .
Open the browser and navigate to the HtmlTextAreaTag .jsp page.
Your browser displays the following page.

Now write any data in to the textarea of  HtmlTextAreaTag .jsp , and click submit button .


Output:


HtmlTextAreaTag .jsp  page and O/P displays the working of  <html:textarea> tag.