Now the next step in this tutorial passes the values of variables in the java
web form to a jsp file instead of embedding them in println commands. Here is
the code that the tutorial (https://www.youtube.com/watch?v=eP9oz6ZKUXM at
Creat JavaServer Page (JSP), about 23 minutes into it) gives:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
float miles = Float.parseFloat(request.getParameter("miles"));
float kilometers = miles * 1.61f;
request.setAttribute("miles", miles);
request.setAttribute("kilometers", kilometers);
String resultPage = "result.jsp";
RequestDispatcher dispatcher = request.getRequestDispatcher(resultPage);
dispacther.forward(request, response);
}
I get a compile error that complains about that RequestDispatcher is an
undefined symbol. After much hunting on websites for answers, I revised the
code as in the project in the git:
https://github.com/the-sanskrit-library/public.git, namely:
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
float miles = Float.parseFloat(request.getParameter("miles"));
float kilometers = miles * 1.61f;
request.setAttribute("miles", miles);
request.setAttribute("kilometers", kilometers);
String resultPage = "result.jsp";
request.getRequestDispatcher(resultPage).forward(request, response);
}
Which compiles. However, the response I get give the string rather than their
values:
Unit Conversion Result
$(miles) miles = $(kilometers) kilometers
Any suggestions?
Yours,
Peter
******************************
Peter M. Scharf, President
The Sanskrit Library
[email protected]
https://sanskritlibrary.org
******************************
> On Jan 20, 2023, at 12:31 PM, Carl Mosca <[email protected]> wrote:
>
> You're welcome Peter and glad to hear it. You can remove/replace the root
> app if/as needed.
>
> Regards,
> Carl
>
> On Fri, Jan 20, 2023 at 1:28 PM Peter Scharf <[email protected]
> <mailto:[email protected]>> wrote:
>> Dear Carl,
>> Thanks for your help. I installed Tomcat version 9. Now the project
>> runs correctly.
>> Changing the context path to “/” however, interfered with the “It
>> works” root app of Tomcat, so I changed it back. I get the correct result
>> of the conversion servlet at the path
>> http://localhost:8080/mavenproject3/convert.
>> Yours,
>> Peter
>>
>> ******************************
>> Peter M. Scharf, President
>> The Sanskrit Library
>> [email protected] <mailto:[email protected]>
>> https://sanskritlibrary.org <https://sanskritlibrary.org/>
>> ******************************
>>
>>> On Jan 18, 2023, at 8:16 PM, Carl Mosca <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>
>>> Hi Peter,
>>>
>>> First off it looks like the example notes suggest using Tomcat 9 or earlier
>>> so I used 9.0.71.
>>>
>>> I changed the context path (in the context.xml file): <Context path="/"/>.
>>>
>>> It's worth looking at creating a .gitignore file so that class and other
>>> binaries are not in git as they are not needed.
>>>
>>> Regards,
>>> Carl
>>>
>>> On Wed, Jan 18, 2023 at 6:16 PM Peter Scharf <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>> The catalina log has lots of info entries. Here’s one WARNING:
>>>>
>>>> 18-Jan-2023 12:10:12.964 WARNING [main]
>>>> org.apache.catalina.startup.HostConfig.deployDescriptor The path attribute
>>>> with value [/mavenproject3] in deployment descriptor
>>>> [/usr/local/apache-tomcat-10.0.23/conf/Catalina/localhost/mavenproject3.xml]
>>>> has been ignored
>>>>
>>>> The catalina.out file has the same suspicious entry:
>>>>
>>>> 18-Jan-2023 12:10:12.964 WARNING [main]
>>>> org.apache.catalina.startup.HostConfig.deployDescriptor The path attribute
>>>> with value [/mavenproject3] in deployment descriptor
>>>> [/usr/local/apache-tomcat-10.0.23/conf/Catalina/localhost/mavenproject3.xml]
>>>> has been ignored
>>>>
>>>> The localhost_access_log.2023-01-18.txt file has:
>>>>
>>>> 0:0:0:0:0:0:0:1 - - [18/Jan/2023:12:10:18 -0600] "GET /convert HTTP/1.1"
>>>> 404 759
>>>> 0:0:0:0:0:0:0:1 - - [18/Jan/2023:12:10:18 -0600] "GET /favicon.ico
>>>> HTTP/1.1" 200 21630
>>>> 0:0:0:0:0:0:0:1 - - [18/Jan/2023:16:50:07 -0600] "GET /mavenproject3/
>>>> HTTP/1.1" 200 453
>>>> 0:0:0:0:0:0:0:1 - - [18/Jan/2023:16:50:14 -0600] "POST
>>>> /mavenproject3/convert HTTP/1.1" 404 777
>>>> 0:0:0:0:0:0:0:1 - - [18/Jan/2023:16:51:11 -0600] "POST
>>>> /mavenproject3/convert HTTP/1.1" 404 777
>>>>
>>>> Regarding Java EE versus Jakarta EE, a quick search shows that none of my
>>>> project files contain ‘jakarta’ while the following all contain ‘java’
>>>>
>>>> UnitConverterServlet.class
>>>> UnitConverterServlet.class
>>>> UnitConverterServlet.java
>>>> inputFiles.lst
>>>> javaee-endorsed-api-7.0.jar
>>>> pom.xml
>>>>
>>>>
>>>>
>>>> ******************************
>>>> Peter M. Scharf, President
>>>> The Sanskrit Library
>>>> [email protected] <mailto:[email protected]>
>>>> https://sanskritlibrary.org <https://sanskritlibrary.org/>
>>>> ******************************
>>>>
>>>>> On Jan 18, 2023, at 12:19 PM, Eric Bresie <[email protected]
>>>>> <mailto:[email protected]>> wrote:
>>>>>
>>>>> Does anything show up in tomcat log?
>>>>>
>>>>> I seem to recall there is some migration going on to move namespace from
>>>>> Java EE to jakarta EE name space. Not sure if maybe that is coming into
>>>>> play here. This might help if it is impacted
>>>>>
>>>>> https://github.com/apache/tomcat-jakartaee-migration
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Jan 18, 2023 at 12:11 PM Peter Scharf <[email protected]
>>>>> <mailto:[email protected]>> wrote:
>>>>>> Thanks, Eric. I had tried that. I get the message:
>>>>>>
>>>>>> HTTP Status 404 – Not Found
>>>>>>
>>>>>> Type Status Report
>>>>>>
>>>>>> Message The requested resource [/convert] is not available
>>>>>>
>>>>>> Description The origin server did not find a current representation for
>>>>>> the target resource or is not willing to disclose that one exists.
>>>>>>
>>>>>> Apache Tomcat/10.0.23
>>>>>>
>>>>>>
>>>>>> ******************************
>>>>>> Peter M. Scharf, President
>>>>>> The Sanskrit Library
>>>>>> [email protected] <mailto:[email protected]>
>>>>>> https://sanskritlibrary.org <https://sanskritlibrary.org/>
>>>>>> ******************************
>>>>>>
>>>>>>> On Jan 18, 2023, at 12:06 PM, Eric Bresie <[email protected]
>>>>>>> <mailto:[email protected]>> wrote:
>>>>>>>
>>>>>>>
>>>>>>> Servlet says the urlpattern is “/convert”
>>>>>>>
>>>>>>> Try
>>>>>>> http://localhost:8080/convert
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Jan 18, 2023 at 11:51 AM Peter Scharf
>>>>>>> <[email protected] <mailto:[email protected]>> wrote:
>>>>>>>> Yes, the URL is correct:
>>>>>>>> https://github.com/the-sanskrit-library/public.git
>>>>>>>> The git directory hierarchy deceived me: I had the code outside the
>>>>>>>> git directory. I have now moved it into the git directory.
>>>>>>>> Forgive me; I’m not very familiar with git and am using the desktop
>>>>>>>> version.
>>>>>>>> Yours,
>>>>>>>> Peter
>>>>>>>>
>>>>>>>> ******************************
>>>>>>>> Peter M. Scharf, President
>>>>>>>> The Sanskrit Library
>>>>>>>> [email protected] <mailto:[email protected]>
>>>>>>>> https://sanskritlibrary.org <https://sanskritlibrary.org/>
>>>>>>>> ******************************
>>>>>>>>
>>>>>>>>> On Jan 18, 2023, at 5:35 AM, Carl Mosca <[email protected]
>>>>>>>>> <mailto:[email protected]>> wrote:
>>>>>>>>>
>>>>>>>>> Hi Peter,
>>>>>>>>>
>>>>>>>>> Can you confirm that url please. I am not seeing Java code there;
>>>>>>>>> only a README and attribute file.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>> Carl
>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Tue, Jan 17, 2023 at 10:40 PM Peter Scharf
>>>>>>>>> <[email protected] <mailto:[email protected]>>
>>>>>>>>> wrote:
>>>>>>>>>> Thank you for suggesting to put the project on Github. I have now
>>>>>>>>>> created a public repository at the following url:
>>>>>>>>>>
>>>>>>>>>> https://github.com/the-sanskrit-library/public.git
>>>>>>>>>>
>>>>>>>>>> The project is in the NetBeans directory.
>>>>>>>>>> Yours,
>>>>>>>>>> Peter
>>>>>>>>>>
>>>>>>>>>> ******************************
>>>>>>>>>> Peter M. Scharf, President
>>>>>>>>>> The Sanskrit Library
>>>>>>>>>> [email protected] <mailto:[email protected]>
>>>>>>>>>> https://sanskritlibrary.org <https://sanskritlibrary.org/>
>>>>>>>>>> ******************************
>>>>>>>>>>
>>>>>>>>>>> On Jan 17, 2023, at 2:38 PM, Carl Mosca <[email protected]
>>>>>>>>>>> <mailto:[email protected]>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hello Peter,
>>>>>>>>>>>
>>>>>>>>>>> Is the project that you created somewhere (such as Github) such
>>>>>>>>>>> that folks could take a look at it?
>>>>>>>>>>>
>>>>>>>>>>> Regards,
>>>>>>>>>>> Carl
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Jan 16, 2023 at 11:21 PM Peter Scharf
>>>>>>>>>>> <[email protected] <mailto:[email protected]>>
>>>>>>>>>>> wrote:
>>>>>>>>>>>> I just installed NetBeans 16 on a MacBook Pro with an M chip:
>>>>>>>>>>>>
>>>>>>>>>>>> Product Version: Apache NetBeans IDE 16
>>>>>>>>>>>> Java: 19.0.1; OpenJDK 64-Bit Server VM 19.0.1
>>>>>>>>>>>> Runtime: OpenJDK Runtime Environment 19.0.1
>>>>>>>>>>>> System: Mac OS X version 13.0.1 running on aarch64; UTF-8; en_US
>>>>>>>>>>>> (nb)
>>>>>>>>>>>>
>>>>>>>>>>>> I am trying to create a minimal servlet and war file to use with
>>>>>>>>>>>> Tomcat
>>>>>>>>>>>>
>>>>>>>>>>>> apache-tomcat-10.0.23
>>>>>>>>>>>>
>>>>>>>>>>>> I worked through half of the demo How to create a webapp tutorial
>>>>>>>>>>>> at: https://www.youtube.com/watch?v=eP9oz6ZKUXM
>>>>>>>>>>>> which, however, uses NetBeans 12 and other older software than I
>>>>>>>>>>>> have installed.
>>>>>>>>>>>> I was able to do the first item successfully with minor
>>>>>>>>>>>> adaptations:
>>>>>>>>>>>> 1. Create a Jave Web project with Maven
>>>>>>>>>>>> Got build error:
>>>>>>>>>>>> https://stackoverflow.com/questions/66920567/error-injecting-org-apache-maven-plugin-war-warmojo
>>>>>>>>>>>> Went to: https://maven.apache.org/plugins/
>>>>>>>>>>>> Answer: manually configuring one of the recent war plug-ins in
>>>>>>>>>>>> POM.xml
>>>>>>>>>>>> Changed 2.3 to 3.3.2
>>>>>>>>>>>> Then got the form.
>>>>>>>>>>>> I successfully created the Unit Conversion form which opens in
>>>>>>>>>>>> Safari (Version 16.1) in tomcat:
>>>>>>>>>>>> http://localhost:8080/mavenproject3/
>>>>>>>>>>>>
>>>>>>>>>>>> But trying the second—third items:
>>>>>>>>>>>> 2. Create Java Servlet & JavaServer Page (JSP)
>>>>>>>>>>>> 3. Run Java Web App on Tomcat inside NetBeans
>>>>>>>>>>>>
>>>>>>>>>>>> I got stuck.
>>>>>>>>>>>> When I fill in a value in the miles box and click Convert to
>>>>>>>>>>>> kilometers, Safari gives me a
>>>>>>>>>>>> HTTP Status 404 – Not Found
>>>>>>>>>>>> Message The requested resource [/mavenproject3/convert] is not
>>>>>>>>>>>> available
>>>>>>>>>>>> Description The origin server did not find a current
>>>>>>>>>>>> representation for the target resource or is not willing to
>>>>>>>>>>>> disclose that one exists.
>>>>>>>>>>>>
>>>>>>>>>>>> After a couple of days trying to fix it, I’m still at a loss.
>>>>>>>>>>>> I did get rid of a problem not finding the native tomcat libraries:
>>>>>>>>>>>> INFO [main]
>>>>>>>>>>>> org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The
>>>>>>>>>>>> Apache Tomcat Native library which allows using OpenSSL was not
>>>>>>>>>>>> found on the java.library.path: ...
>>>>>>>>>>>> by dowloading and installing The Apache Tomcat Native library
>>>>>>>>>>>> following instructions here:
>>>>>>>>>>>> https://formulae.brew.sh/formula/tomcat-native
>>>>>>>>>>>>
>>>>>>>>>>>> However, I still get the 404 not found in Safari.
>>>>>>>>>>>> Can anyone help me?
>>>>>>>>>>>>
>>>>>>>>>>>> I wonder whether these debugger messages indicate a problem using
>>>>>>>>>>>> a symbolic link to my real tomcat directory from /Library/Tomcat
>>>>>>>>>>>>
>>>>>>>>>>>> 16-Jan-2023 11:15:13.009 INFO [main]
>>>>>>>>>>>> org.apache.catalina.startup.VersionLoggerListener.log Command line
>>>>>>>>>>>> argument: -Dignore.endorsed.dirs=
>>>>>>>>>>>> 16-Jan-2023 11:15:13.010 INFO [main]
>>>>>>>>>>>> org.apache.catalina.startup.VersionLoggerListener.log Command line
>>>>>>>>>>>> argument: -Dcatalina.base=/Library/Tomcat
>>>>>>>>>>>> 16-Jan-2023 11:15:13.010 INFO [main]
>>>>>>>>>>>> org.apache.catalina.startup.VersionLoggerListener.log Command line
>>>>>>>>>>>> argument: -Dcatalina.home=/Library/Tomcat
>>>>>>>>>>>>
>>>>>>>>>>>> but the infos in the debugger do tell me that it is using the real
>>>>>>>>>>>> directories:
>>>>>>>>>>>> CATALINA_BASE: /usr/local/apache-tomcat-10.0.23
>>>>>>>>>>>> CATALINA_HOME: /usr/local/apache-tomcat-10.0.23
>>>>>>>>>>>>
>>>>>>>>>>>> I get the following debugger WARNING:
>>>>>>>>>>>> WARNING [http-nio-8080-exec-10]
>>>>>>>>>>>> org.apache.catalina.startup.HostConfig.deployDescriptor The path
>>>>>>>>>>>> attribute with value [/mavenproject3] in deployment descriptor
>>>>>>>>>>>> [/usr/local/apache-tomcat-10.0.23/conf/Catalina/localhost/mavenproject3.xml]
>>>>>>>>>>>> has been ignored
>>>>>>>>>>>>
>>>>>>>>>>>> Trying to follow suggestions at:
>>>>>>>>>>>> https://stackoverflow.com/questions/11731377/servlet-returns-http-status-404-the-requested-resource-servlet-is-not-availa
>>>>>>>>>>>> I’m lost. I can’t even figure out which versions of Servlet I’m
>>>>>>>>>>>> using, and the instructions to find out at.:
>>>>>>>>>>>> https://stackoverflow.com/questions/3913485/how-do-i-know-what-version-of-servlet-api-jar-i-have
>>>>>>>>>>>>
>>>>>>>>>>>> don’t provide enough context for me to know where to put the
>>>>>>>>>>>> commands suggested.
>>>>>>>>>>>>
>>>>>>>>>>>> ===
>>>>>>>>>>>> Can anyone help me either (a) work through this tutorial with
>>>>>>>>>>>> current versions of software, or (b) give me an example of how to
>>>>>>>>>>>> create a servlet or portable war file in NetBeans to use with
>>>>>>>>>>>> Tomcat by copying it to its webapps directory using current
>>>>>>>>>>>> versions of NetBeans and other software?
>>>>>>>>>>>>
>>>>>>>>>>>> Thank you in advance.
>>>>>>>>>>>> Yours,
>>>>>>>>>>>>
>>>>>>>>>>>> ******************************
>>>>>>>>>>>> Peter M. Scharf, President
>>>>>>>>>>>> The Sanskrit Library
>>>>>>>>>>>> [email protected] <mailto:[email protected]>
>>>>>>>>>>>> https://sanskritlibrary.org <https://sanskritlibrary.org/>
>>>>>>>>>>>> ******************************
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> Carl J. Mosca
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Carl J. Mosca
>>>>>>>>
>>>>>>> --
>>>>>>> Eric Bresie
>>>>>>> [email protected] <mailto:[email protected]>
>>>>>>
>>>>> --
>>>>> Eric Bresie
>>>>> [email protected] <mailto:[email protected]>
>>>>
>>>
>>>
>>> --
>>> Carl J. Mosca
>>
>
>
> --
> Carl J. Mosca