[JAVA] JSP on tomcat

Introduction

As a starting point for web application development, I wanted to run JSP in a local environment. Since it took time to build the environment, I made a memo instead of a memorandum.

What I wanted to do

JSP?Servlet? Apparently, unlike PHP, Java is divided into JSP that draws the client side and Servlet that processes the server side.

Use Servlets and JSPs to create Java applications that run on the server side. Servlets and JSPs basically do the same thing, but Servlets are written like Java programs, while JSPs are written like a scripting language like PHP. Therefore, JSP is suitable for creating the screen display part, and it is suitable to create the part that works on the back end such as the connection with the database with the servlet. Introduction to Servlet / JSP

It's a different part from PHP. However, at this time of the year, I wonder if there are few opportunities to touch the JSP directly ... I have to read and study Around here (Web development with Java in 2015).

Environment

Apparently, Apache basically handles the Web content, but it seems that Tomcat's power is required to execute JSP / Java Servlet. XAMPP has prepared the area in good condition, so you can use it just by starting the service. As expected.

procedure

So let's generate a web page right away.

Start tomcat

178.JPG Start the "Tomcat" service from the XAMPP control panel.

Connect to the console

179.JPG From the web browser, enter "http : // localhost: 8080". If the above screen is displayed, you can confirm that Tomcat has started normally.

Add a directory to the root directory

180.JPG By default, "C: \ xampp \ tomcat \ webapps" is the root directory. I created a new "hellojsp" here.

Create a jsp file in hellojsp

Source code

<%@
	page import="java.util.*"
	contentType="text/html; charset=utf8"
%>
<!DOCTYPE html>
<html>
<head>
	<title>JSP</title>
</head>
<body>
	<%
		java.util.Date nowTime = new java.util.Date();
	%>
	<h1>Hello, world! Now time is <strong><% out.print(nowTime); %></strong>.</h1>
</body>
</html>

Access the sample page from a web browser

181.JPG Access the created "http : // localhost: 8080 / hellojsp / index.jsp". Confirm that the sample page is displayed.

Impressions

It was an ordinary setting. Looking back now, where did I get hooked on my past self ... Understand the directory structure of Tomcat Dekitena Kattakara Nano Kanner (bar) This area (let's understand the directory structure of Tomcat) explains in detail. By the way, next is Java Servlet.

Recommended Posts

JSP on tomcat
Tomcat v8 on CentOS7
About [servlet] [JSP] [tomcat]
1002 error on tomcat + webSocket
Run JSP Hello World with Tomcat on Docker
Install tomcat on Sakura's VPS
Install tomcat + eclipse on mac
moved! JSF + CDI (Preferences) on Tomcat
Run tomcat shell script on java8
tomcat error
Change JDK and Tomcat versions on CentOS
Deploy Java Servlet app locally on Tomcat
Relative path when running tomcat on eclipse
Build Apache + Tomcat + Pebble locally on Mac
Notes on JSP extension tags in SpringFrameWork
Build Apache / Tomcat development environment on Cent OS 7
[Eclipse / Tomcat] Servlet + JSP in Maven webapp project
moved! JSF + CDI on Tomcat and Bean Validation
Install Java, Apache, Tomcat9 on EC2 (Amazon Linux2)