|
|
- 最近のカキコ -
2008/01/30 / 08:02
うそですw その他 / TRACKBACK(0) / COMMENT(0) / PAGETOP 2008/01/29 / 21:45
ちょwww
![]() ポケモン / TRACKBACK(0) / COMMENT(0) / PAGETOP 2008/01/29 / 20:21
( ^ω^)おっおっおっ ポケモン / TRACKBACK(0) / COMMENT(0) / PAGETOP 2008/01/29 / 19:43
ちょっと、場所移動して釣ってたら。 ポケモン / TRACKBACK(0) / COMMENT(0) / PAGETOP 2008/01/29 / 18:04
<ポケモンパール> ポケモン / TRACKBACK(0) / COMMENT(0) / PAGETOP 2008/01/28 / 21:17
備忘録 workspace(Eclipseの作業ディレクトリ)/JSP_Servlet(プロジェクト名)WebContent/WEB-INF/web.xml web.xmlファイルを作成して保存しておく。 (Javaサーブレットが使えるようになるweb.xmlファイル) Eclipse3.3が作ってくれたweb.xmlを、Javaサーブレットが使えるように変更したものを、コピペしたもの。
<!-- web.xml --> Java / TRACKBACK(0) / COMMENT(0) / PAGETOP 2008/01/28 / 19:09
エンゼルプリン88円だったので、即買いしてきました。 2008/01/28 / 03:50
備忘録
<URL> 移動する流れ http://localhost:8080/JSP_Servlet/index.html ↓ http://localhost:8080/JSP_Servlet/Sample1 (Sample1は、おそらくSample1.javaファイルを、コンパイルして出来た、Sample1.classファイル) ↓↑ http://localhost:8080/JSP_Servlet/result.jsp
<サーブレット利用準備> 実行環境:Eclipse3.3 + Tomcat6.0
<ファイルの格納場所> ・index.html ・Sample1.java ・result.jsp この3つのファイルは、プロジェクト新規作成時、「動的Webプロジェクト」より、プロジェクト名:JSP_Servletを作成し、(図 - 1)のように配置する。
<画面遷移>
画面表示の流れは、(図 - 2)のようになる。
(図 - 1) ![]() (図 - 2) ![]() Java / TRACKBACK(0) / COMMENT(0) / PAGETOP 2008/01/28 / 01:18
備忘録
<!-- サーブレットプログラム -->
<!-- index.html --> <?xml version="1.0" encoding="Shift_JIS" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" /> <title>サーブレットプログラム</title> </head> <body> <form method="get" action="./Sample1"> <input type="text" name="hoge" /><input type="submit" value="送信" /> </form> </body> </html>
/*Javaサーブレットプログラム*/
//Sample1.java import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @SuppressWarnings("serial") public class Sample1 extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //値を取得 String foo = new String(request.getParameter("hoge").getBytes("8859_1"),"JISAutoDetect"); //取得した値を加工 foo += "(HTML)<br />" + "↓<br />" + "セッション開始[set]<br />" + "(Javaサーブレット)"; //セッションを開始 HttpSession session = request.getSession(true); /*セッションで情報をセット*/ session.setAttribute("bar",foo); /*JSPを呼び出す*/ //ドキュメントルートからの絶対パス指定(パス"./"は無効。"/"文字から始める。) String send = "/result.jsp"; /*リダイレクト*/ //http://localhost:8080/Schedule_project2/result.jsp で表示。 //response.sendRedirect(send); /*フォワード*/ //http://localhost:8080/Schedule_project2/Sample1で表示。 getServletContext().getRequestDispatcher(send).forward(request,response); } }
<%-- JSP/サーブレットプログラム --%>
<%-- rusult.jsp --%> <?xml version="1.0" encoding="Shift_JIS" ?> <%@ page language="java" contentType="text/html; charset=Shift_JIS" pageEncoding="Shift_JIS"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" /> <title>JSP/サーブレット</title> </head> <body> <% /*セッションで情報をゲット*/ String baz = (String)session.getAttribute("bar"); %> 結果表示:<br /> <br /> <%=baz %><br /> ↓<br /> セッション終了[get]<br /> (JSP/サーブレット)<br /> <br /> <a href="./index.html">Topへもどる</a> </body> </html> Java / TRACKBACK(0) / COMMENT(24) / PAGETOP |