SAK }‘ŠÙ

SAK Streets ƒƒCƒ“ƒXƒgƒŠ[ƒg }‘ŠÙEƒJƒtƒF ˆê—— SAK Streets ŒŸõ
| VB | SQL | Perl | PHP | ASP | JSP | C | PC | HP | FAQ | ƒtƒŠ[ƒ\ƒtƒg |

JAVA ServletAJSP Šî‘b•Ò7 - ƒtƒH[ƒ€ƒŠƒNƒGƒXƒgAƒNƒGƒŠ[ƒŠƒNƒGƒXƒgA“ú–{Œê

¡ƒtƒH[ƒ€ƒŠƒNƒGƒXƒg(Servlet)

  Emethod="post" ‚É‚æ‚郊ƒNƒGƒXƒg‚ÍAŽŸ‚̂悤‚É‚·‚éB
    Servlet ‘¤‚Å‚ÍAdoPost ƒƒ\ƒbƒhƒI[ƒo[ƒ‰ƒCƒh‚É‚æ‚èA
    req.getParameter("name"); ‚Ńf[ƒ^‚ðˆø‚«Žæ‚éB

  E”’l‚É•ÏŠ·‚·‚é‚É‚ÍA
     int p1 = Integer.parseInt(req.getParameter("a"));
    “™‚ðŽg—p‚·‚éB
    ’A‚µAnull ‚Ü‚½‚ÍA”’l•ÏŠ·–³Œøƒf[ƒ^‚Å‚Í—áŠO‚ª”­¶‚·‚éB

  Eƒf[ƒ^‚Ì“ú–{Œê•”•ª‚ªA‚¤‚Ü‚­ˆø‚«Žæ‚ê‚È‚¢B(^^;
    ’²¸‚ÌŒ‹‰ÊATomcat ‚Ì server.xml ‚ɃR[ƒh•ÏŠ·‚ÌŽw’肪•K—v‚Æ”»–¾‚µ‚½B
    ŽŸ‚̂悤‚É server.xml ‚ÌÅŒã‚É <Context>...</Context> ‚ð’ljÁ‚µ‚½B

...
...
...
    </ContextManager>
    <Context path="/sak" docBase="webapps/sak" debug="0" reloadable="true">
      <DecodeInterceptor defaultEncoding="Shift_JIS" useSessionEncoding="false" />
    </Context>
</Server>

  E‚±‚ÌC³ŒãATomcat ‚ðÄ‹N“®‚·‚é‚ÆA“ú–{Œê‚ªˆ—‚Å‚«‚é‚悤‚É‚È‚éB
    PerlAPHPAASP ‚É”äŠr‚µ‚ÄA‚Ç‚¤‚à‚±‚Ì‚Ö‚ñ‚Í–Ê“|‚Å‚ ‚éB

<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<TITLE>ƒtƒH[ƒ€ƒŠƒNƒGƒXƒgƒeƒXƒg</TITLE>
</HEAD>
<BODY>
<P align="center">¥ ƒtƒH[ƒ€ƒŠƒNƒGƒXƒgƒeƒXƒg ¥</P>
<HR>
<DIV>
<FORM action="sak/servlet/test?c=123" id="FORM1" method="post" NAME="FORM1">
<TABLE border=1 cellPadding=3 cellSpacing=1>
  <TBODY>
    <TR>
      <TD nowrap><FONT size="-1">ƒpƒ‰ƒƒ^ a</FONT></TD>
      <TD nowrap><INPUT id="a" NAME="a" type="text" size="42" maxlength="40" value=""></TD>
    </TR>
    <TR>
      <TD nowrap><FONT size="-1">ƒpƒ‰ƒƒ^ b</FONT></TD>
      <TD nowrap><INPUT id="b" NAME="b" type="text" size="42" maxlength="40" value=""></TD>
    </TR>
  </TBODY>
</TABLE>
<BR>
<TABLE border=1 cellPadding=3 cellSpacing=1>
  <TBODY>
    <TR>
      <TD nowrap><INPUT id=submit1 NAME=submit1 type=submit value="  ŽÀs  "></TD>
      <TD nowrap><INPUT id=reset1 NAME=reset1 type=reset value="ƒŠƒZƒbƒg"></TD>
    </TR>
  </TBODY>
</TABLE>
</FORM>
</DIV>
<HR>
</BODY>
</HTML>

// test.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class test extends HttpServlet {

  public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
    res.setContentType("text/html; charset=SJIS");
    PrintWriter rw = res.getWriter();
    String p1 = req.getParameter("a");
    String p2 = req.getParameter("b");
    String p3 = req.getParameter("c");
    rw.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">");
    rw.println("<HTML>");
    rw.println("<HEAD>");
    rw.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\">");
    rw.println("<TITLE>JAVA Servlet Test</TITLE>");
    rw.println("</HEAD>");
    rw.println("<BODY>");
    if (p1.equals("")) {
      rw.println("<P>ƒpƒ‰ƒƒ^ a = ‹ó</P>");
    }
    else {
      rw.println("<P>ƒpƒ‰ƒƒ^ a = " + p1 + "</P>");
    }
    if (p2.equals("")) {
      rw.println("<P>ƒpƒ‰ƒƒ^ b = ‹ó</P>");
    }
    else {
      rw.println("<P>ƒpƒ‰ƒƒ^ b = " + p2 + "</P>");
    }
    if (p3.equals("")) {
      rw.println("<P>ƒpƒ‰ƒƒ^ c = ‹ó</P>");
    }
    else {
      rw.println("<P>ƒpƒ‰ƒƒ^ c = " + p3 + "</P>");
    }
    rw.println("</BODY>");
    rw.println("</HTML>");
  }

}

¡ƒtƒH[ƒ€ƒŠƒNƒGƒXƒg(JSP)

<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<TITLE>ƒtƒH[ƒ€ƒŠƒNƒGƒXƒgƒeƒXƒg</TITLE>
</HEAD>
<BODY>
<P align="center">¥ ƒtƒH[ƒ€ƒŠƒNƒGƒXƒgƒeƒXƒg ¥</P>
<HR>
<DIV>
<FORM action="sak/jsp/test.jsp?c=123" id="FORM1" method="post" NAME="FORM1">
<TABLE border=1 cellPadding=3 cellSpacing=1>
  <TBODY>
    <TR>
      <TD nowrap><FONT size="-1">ƒpƒ‰ƒƒ^ a</FONT></TD>
      <TD nowrap><INPUT id="a" NAME="a" type="text" size="42" maxlength="40" value=""></TD>
    </TR>
    <TR>
      <TD nowrap><FONT size="-1">ƒpƒ‰ƒƒ^ b</FONT></TD>
      <TD nowrap><INPUT id="b" NAME="b" type="text" size="42" maxlength="40" value=""></TD>
    </TR>
  </TBODY>
</TABLE>
<BR>
<TABLE border=1 cellPadding=3 cellSpacing=1>
  <TBODY>
    <TR>
      <TD nowrap><INPUT id=submit1 NAME=submit1 type=submit value="  ŽÀs  "></TD>
      <TD nowrap><INPUT id=reset1 NAME=reset1 type=reset value="ƒŠƒZƒbƒg"></TD>
    </TR>
  </TBODY>
</TABLE>
</FORM>
</DIV>
<HR>
</BODY>
</HTML>

<%@ page import="java.util.*" contentType="text/html; charset=Shift_JIS"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<TITLE>JAVA Server Page(JSP) Test</TITLE>
</HEAD>
<BODY>
<%
  String p1 = request.getParameter("a");
  String p2 = request.getParameter("b");
  String p3 = request.getParameter("c");

  if (p1.equals("")) {
    out.println("<P>ƒpƒ‰ƒƒ^ a = ‹ó</P>");
  }
  else {
    out.println("<P>ƒpƒ‰ƒƒ^ a = " + p1 + "</P>");
  }
  if (p2.equals("")) {
    out.println("<P>ƒpƒ‰ƒƒ^ b = ‹ó</P>");
  }
  else {
    out.println("<P>ƒpƒ‰ƒƒ^ b = " + p2 + "</P>");
  }
  if (p3.equals("")) {
    out.println("<P>ƒpƒ‰ƒƒ^ c = ‹ó</P>");
  }
  else {
    out.println("<P>ƒpƒ‰ƒƒ^ c = " + p3 + "</P>");
  }
%>
</BODY>
</HTML>

¡ƒNƒGƒŠ[ƒŠƒNƒGƒXƒg(Servlet)

  EQUERY_STRING ‚É‚æ‚郊ƒNƒGƒXƒg‚ÍAŽŸ‚̂悤‚É‚·‚éB
    Servlet ‘¤‚Å‚ÍAdoGet ƒƒ\ƒbƒhƒI[ƒo[ƒ‰ƒCƒh‚É‚æ‚èA
    req.getParameter("name"); ‚Ńf[ƒ^‚ðˆø‚«Žæ‚éB
    ®A–¢Žw’è‚Ì QUERY_STRING ‚ÍANullPointerException ‚ŃGƒ‰[‚É‚È‚éB
    if (req.getParameter("a") != null) ‚ÅAƒpƒ‰ƒƒ^Žw’è—L–³‚̃`ƒFƒbƒN‚ð
    s‚Á‚½B

http://localhost/sak/servlet/test?b=123&c=456
http://localhost/sak/servlet/test?a=abc&b=123&c=456

// test.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class test extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
    res.setContentType("text/html; charset=SJIS");
    PrintWriter rw = res.getWriter();
    String p1 = "";
    String p2 = "";
    String p3 = "";
    if (req.getParameter("a") != null) {
      p1 = req.getParameter("a");
    }
    if (req.getParameter("b") != null) {
      p2 = req.getParameter("b");
    }
    if (req.getParameter("c") != null) {
      p3 = req.getParameter("c");
    }
    rw.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">");
    rw.println("<HTML>");
    rw.println("<HEAD>");
    rw.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\">");
    rw.println("<TITLE>JAVA Servlet Test</TITLE>");
    rw.println("</HEAD>");
    rw.println("<BODY>");
    if (p1.equals("")) {
      rw.println("<P>ƒpƒ‰ƒƒ^ a = ‹ó</P>");
    }
    else {
      rw.println("<P>ƒpƒ‰ƒƒ^ a = " + p1 + "</P>");
    }
    if (p2.equals("")) {
      rw.println("<P>ƒpƒ‰ƒƒ^ b = ‹ó</P>");
    }
    else {
      rw.println("<P>ƒpƒ‰ƒƒ^ b = " + p2 + "</P>");
    }
    if (p3.equals("")) {
      rw.println("<P>ƒpƒ‰ƒƒ^ c = ‹ó</P>");
    }
    else {
      rw.println("<P>ƒpƒ‰ƒƒ^ c = " + p3 + "</P>");
    }
    rw.println("</BODY>");
    rw.println("</HTML>");
  }

}

¡ƒNƒGƒŠ[ƒŠƒNƒGƒXƒg(JSP)

<%@ page import="java.util.*" contentType="text/html; charset=Shift_JIS"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<TITLE>JAVA Server Page(JSP) Test</TITLE>
</HEAD>
<BODY>
<%
  String p1 = "";
  String p2 = "";
  String p3 = "";
  if (request.getParameter("a") != null) {
    p1 = request.getParameter("a");
  }
  if (request.getParameter("b") != null) {
    p2 = request.getParameter("b");
  }
  if (request.getParameter("c") != null) {
    p3 = request.getParameter("c");
  }

  if (p1.equals("")) {
    out.println("<P>ƒpƒ‰ƒƒ^ a = ‹ó</P>");
  }
  else {
    out.println("<P>ƒpƒ‰ƒƒ^ a = " + p1 + "</P>");
  }
  if (p2.equals("")) {
    out.println("<P>ƒpƒ‰ƒƒ^ b = ‹ó</P>");
  }
  else {
    out.println("<P>ƒpƒ‰ƒƒ^ b = " + p2 + "</P>");
  }
  if (p3.equals("")) {
    out.println("<P>ƒpƒ‰ƒƒ^ c = ‹ó</P>");
  }
  else {
    out.println("<P>ƒpƒ‰ƒƒ^ c = " + p3 + "</P>");
  }
%>
</BODY>
</HTML>

¡JAVA ServletAJSP Šî‘b•ÒŽ‘—¿
¡JAVA ServletAJSP + PostgreSQL •ÒŽ‘—¿
¡JAVA ServletAJSP + Oracle9i •ÒŽ‘—¿
¡PostgreSQL •ÒAJAVA ServletAJSP •ÒŽ‘—¿
¡MySQL •ÒŽ‘—¿
¡SQL Šî‘b•ÒŽ‘—¿
¡SQL Šî‘bŽÀ’n•ÒŽ‘—¿
¡SQL ƒ`ƒ…[ƒjƒ“ƒO•ÒŽ‘—¿
¡Oracle PL/SQL •ÒŽ‘—¿
| VB | SQL | Perl | PHP | ASP | JSP | C | PC | HP | FAQ | ƒtƒŠ[ƒ\ƒtƒg |

SAK Streets ƒƒCƒ“ƒXƒgƒŠ[ƒg }‘ŠÙEƒJƒtƒF ˆê—— SAK Streets ŒŸõ



Copyright (C) 1999-2024 Y.SAK