JSP/Servlet | JSP(Java Server Pages) | Running JSP
Now you need to deploy the project and check that it works, but deploying every time you make a small change would be slow and troublesome. So here, we will explain how to check the project’s behavior in the local environment.
-
In Project Explorer, select the project folder to run, the “MyGaeApp” folder.
-
From the [Run] menu, select “Web Application” under the [Run As …] submenu. This starts the built-in Java server and runs the project there.
When the built-in server starts, visit “http://localhost:8888/hello.jsp”. The hello.jsp you created is displayed. Is the current time value already written with <%= %> displayed? This means the statement <%= java.util.Calendar.getInstance().getTime()%> was executed on the server side and the result, the date text, was displayed.
In this way, you can access the project’s web application by specifying “localhost:8888” as the domain for the internal server. Files placed in “war” can also be accessed by specifying the file name after it.
To stop the server that was started, select the horizontal “Console” view at the bottom and click the red square button shown at the top. This stops the server.
If a red x mark is displayed
In some cases, red x icons may be displayed on the project folder and the “war” folder, preventing the project from running. Unless you wrote something incorrectly in war.xml or appengine-web.xml, or deleted project libraries on your own, the cause is probably that you are using the JRE instead of the JDK. The JDK is what builds Java programs. In contrast, the JRE only runs programs. If the project is built using the JRE, it cannot be built and an error occurs.
Select the “Markers” view at the bottom of the screen. The contents of the errors that occurred are displayed there. If the error message says “Your project must be configured to use a JDK in order to use JSPs”, it is because you are using the JRE. Change the settings as follows.
-
From the [Window] menu, select [Preferences] at the bottom. On Mac, select Preferences from the [Eclipse] menu.
-
A window for various Eclipse settings appears. Setting items are displayed as a hierarchical list on the left side of this window. Find and click “Installed JREs” under the “Java” item.
-
The installed JREs and JDKs are listed, probably only one by default. The currently used item has its checkbox turned on. If this is a JRE, the project will not build properly and an error mark will appear.
-
If no JDK setting exists yet, create one. Click the “Add …” button. A dialog for adding a JDK appears.
-
“Installed JDK Types” is displayed. Select “Standard VM”, which is selected by default.
-
Move to the “JRE Definition” display. Configure the JDK here. First, press the “Directory …” button to the right of the “JRE Home:” item at the top. A dialog for selecting a JRE/JDK folder appears. Select the installed JDK folder and press OK. When the JDK path is set in JRE Home, the other items are also set automatically.
-
Press the “Finish” button as is to close the dialog. The JDK you added is now displayed in the list.
-
Turn on the checkbox for the newly added JDK and press the “OK” button in the dialog to close it.
After changing the project to build using the JDK, the x error mark disappears. After that, you can run or deploy the project normally.
If HTTP ERROR 500 occurs
Or, the project may run, but when you try to display the screen, an error like the following may occur.
... omitted ...
Caused by:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 1 in the generated java file
The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
... omitted ...
In the “Console” window at the bottom of the screen, an error may also appear recommending that you install the latest SDK.
... omitted ....
********************************************************
There is a new version of the SDK available.
-----------
Latest SDK:
Release: 1.9.58
Timestamp: Sat Oct 07 01:48:02 KST 2017
API versions: [1.0]
-----------
Your SDK:
Release: 1.9.34
Timestamp: Fri Feb 12 04:36:15 KST 2016
API versions: [1.0]
-----------
Please visit https://developers.google.com/appengine/downloads for the latest SDK.
********************************************************
... omitted ....
This occurs because of a conflict between the JDK and GAE. In this case, change either the JDK version or GAE. The method for changing the JDK was explained above, so here we will explain how to change GAE.
-
As described in the console window, download the latest SDK from the following URL, https://developers.google.com/appengine/downloads, and save it somewhere appropriate.
-
From the [Window] menu, select [Preferences] at the bottom. On Mac, select Preferences from the [Eclipse] menu.
-
Setting items are displayed as a hierarchical list on the left side of this window. Find and click “App Engine” under the “Google” item.
-
On the App Engine screen, press the “Add” button to add the downloaded SDK. Then select the added SDK and press the “OK” button.
If you run the project again, you should be able to confirm that the error no longer occurs.