//Basic of Java and JSP・Servlet//
A. Java Background
B. Java Structure
C. Class and Method
D. Information Encapsulation and Scope
E. Inheritance
F. AWT/SWING
G. Applet
H. How to create programs
I. Servlet/JSP Overview
J. Servlet
K. JSP
L. Linkage with JSP/Servlet/javaBeans

 Table of contents/Related item

     K JSP

・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・

K-1 Introduction to JSP
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・

K-2 JSP form
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
K-3 Static includes/Dynamic includes
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
K-4 Delivery of web data (POST/GET variables)
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
K-5 JSP to create dynamic pages by web data
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
 Question
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・


K-5-6 JSP to create dynamic pages by Web data

・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・

I will show JSP which creates dynamic pages based on Web data from HTML forms shown in K-4 Delivery of web data (POST/GET variables).
I will show based on the example of displaying the content of the Web data sent by the previous example.
Program List 11.5.1 Example of displaying the sent Web data
<%@ page contentType="text/html;charset=euc-jp" %>
<%
  // get sent parameters
  String text = request.getParameter("text");
  String password = request.getParameter("password");
  String checkbox = request.getParameter("checkbox");
  String radio = request.getParameter("radio");
  String select = request.getParameter("select");
  String textarea = request.getParameter("textarea");

  // convert String Code(ISO8859_1 to EUC-JP)
  // If you will code on Windows System, you should convert it ISO8859_1 to Shift_JIS.
  text = new String(text.getBytes("8859_1"),"EUC-JP"); 
  password = new String(password.getBytes("8859_1"),"EUC-JP"); 
  textarea = new String(textarea.getBytes("8859_1"),"EUC-JP"); 
%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html>
  <head>
    <title>getParameter</title>
  </head> 
  <body>
    <h2 align="center">recieve from HTML form data</h2>
    <table border="1" align="center">
      <tr>
        <td align="right">a line text form:</td> 
        <td align="left"> <%= text %> </td>
      </tr>
      <tr>
        <td align="right">password field:</td> 
        <td align="left"> 
          <%= password %>
        </td>
      </tr>
      <tr>
        <td align="right">check box:</td> 
        <td align="left"> <%= checkbox %> </td>
      </tr> 
      <tr>
        <td align="right">radio button:</td>
        <td align="left"> 
          <%= radio %>
        </td>
      </tr>
      <tr>
        <td align="right">select field:</td> 
        <td align="left"> <%= select %> </td>
      </tr> 
      <tr>
        <td align="right">text area(some lines text field):</td>
        <td align="left"> <%= textarea %> </td>
      </tr> 
    </table>
  </body>
</html>

The following line is added to display Japanese in JSP at the beginning of the above example.

contentType="text/html;charset=euc-jp"

When writing JSP in Windows environment, write "charset = Shift_JIS".
Because the standard character code in JSP is Western European character (ISO8859-1), Japanese language cannot be used well without the setting.

Next, the request.getParameter method is used to receive the data sent from the HTML form.
In the above example, it is as follows:

String text = request.getParameter("text");
The character string is returned in the request.getParameter method, so when handling numbers ("int" type), the Web data sent can be processed as numbers by writing as follows:

int value = Integer.ParseInt(text);

Moreover, in the above example,the character code is converted as follows:

text = new String(text.getBytes("8859_1"),"EUC-JP");

However, when displaying the Web data using the GET method, the character strings are converted from ISO8859-1 to EUC-JP and stored in character string variables, because the data is displayed in browsers with ISO8859-1 which is the standard character code for the output.

*NOTE*
When using the POST method, the character code does not have to be converted.