関連する記事 Pleiades All in One(NEON) で、Windows アプリを作成する手順( WindowBuilder ) Pleiades All in One(NEON) には、Tomcat8 が同梱されているので普通にすぐ使えます。(Tomcat6とTomcat7 も入ってます)(少なくとも単独起動に必要です) プロジェクト作成 ▼ 動的 Web プロジェクトを作成します
![]()
サーブレット作成
初期のソース
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class WebApp
*/
@WebServlet("/WebApp")
public class WebApp extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public WebApp() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
パースペクティブを Java EE にして実行![]()
![]()
JSP 作成
▼ ソースを以下に変更して実行 ( 全て保存して http://localhost:8080/Web1/NewFile.jsp にアクセス )
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP シンプル</title>
</head>
<body>
こんにちは!
</body>
</html>
サーブレットを以下のように変更 変更後、全て保存して実行( サーバは再起動 )![]()
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
@WebServlet("/WebApp")
public class WebApp extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
public WebApp() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PageContext pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
JspWriter out = pageContext.getOut();
response.setContentType("text/html; charset=UTF-8");
out.write("<!DOCTYPE html>\r\n");
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n");
out.write("<title>Insert title here</title>\r\n");
out.write("</head>\r\n");
out.write("<body>\r\n");
out.write("\r\n");
out.write("こんにちは!\r\n");
out.write("\r\n");
out.write("</body>\r\n");
out.write("</html>");
_jspxFactory.releasePageContext(pageContext);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
※ JSP がコンパイルされた結果の java ソースコードより転用しています C:\user\java\Web170415a がワークスペースですC:\user\java\Web170415a\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\Web1\org\apache\jsp\NewFile_jsp.java
|
|
【java : JSPの最新記事】
- Tomcat 7(JSP) : 配列, ArrayList, ループ処理
- XAMPP 内 Tomcat Version 7 の設定と簡単な JSP の実行テスト
- JDK がインストールされていない PC の XAMPP の TOMCAT を Pleiades の JDK8 で動作させる
- JSP : 実行中の .jsp と同じフォルダにあるファイルの実際のパスを取得する
- java(JSP) : テーブル名一覧と列名一覧の取得
- JSP : 単純なデータベースの更新( MySQL ODBC 5.1 Driver でDSNを作成しない接続 )
- javamail 1.4.4 + JSP でとにかくメール送信
- Tomcat7 のインストールと、すぐ簡単にJSPアプリケーションテスト( DB アクセス、入力等 )
- TOMCAT6 をインストールしてサンプルアプリケーションも自動登録する


(少なくとも単独起動に必要です)
プロジェクト作成
▼ 動的 Web プロジェクトを作成します
サーブレット作成
初期のソース
JSP 作成
▼ ソースを以下に変更して実行
( 全て保存して http://localhost:8080/Web1/NewFile.jsp にアクセス )




