Nicholas Evans

Greenhorn
+ Follow
since Feb 03, 2018
Cows and Likes
Cows
Total received
1
In last 30 days
1
Total given
0
Likes
Total received
2
Received in last 30 days
2
Total given
1
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nicholas Evans

Frits Walraven wrote:So, what happens if you go to the following URL in a browser when Tomcat is running?

http://localhost:8080/MyServletA/hello



It takes me to what i expect which is

If you're reading this, it worked! - which is in the java.

Thanks so much for your help, I've changed to .html file and now it is working correctly.
1 week ago
Hello, sorry for slow reply I have been busy at work


This is the web xml so the url pattern is /hello




My structure for all of my files i think is in the correct place.

I have my web.xml in \apache-tomcat-9.0.14\webapps\MyServletA\WEB-INF
I have my MyServletA.war in \apache-tomcat-9.0.14\webapps
I have my test.html in \apache-tomcat-9.0.14\webapps\MyServletA
I have my MyServletA.java in \apache-tomcat-9.0.14\webapps\MyServletA\WEB-INF\src\nl\hello
I have my MyServletA.class in \apache-tomcat-9.0.14\webapps\MyServletA\WEB-INF\classes\nl\hello

In my book it says to just put the code to point to the java file via an href link which is why i was using the link to the file. Is there absolutely no way of doing that?

I also don't get why it explains to do it this way in the book if it's not easy to replicate.

This is in Head first java btw.
1 week ago

Frits Walraven wrote:Did you change the link in your HTML file to something simular to the tutorial?


<form method="GET" action="/HelloWorld/hello">
type some text: <input type="text" name="any" />


<input type="submit">
</form>




No I am even more confused haha.

So i decided to put in what you said into the test.html which is the welcome file in my web.xml which is what contains 'this is an amazing servlet'.

I changed it nothing happened. I then removed the file from the directory - it was in C:\Program Files\Java\apache-tomcat-9.0.14\webapps\MyServletA

in this directory i have the .html and two folders META-INF / WEB-INF.

When i remove the file though and click on http://localhost:8080/MyServletA/ it still sees the page How is this possible as i thought it was opening the page from this directory? This is even after restarting browser / startup.bat

Also in terms of putting something in correctly i tried to put in

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Hello World</h1>
<form method="GET" action="/MyServlet/hello">type some text: <input <br /> type="text" name="any" />



<input type="SUBMIT"></form>
</body>
</html>

I don't really understand the bold, even from the HelloWorld example because the hierarchy isn't that - HelloWorld\WEB-INF\src\nl\hello the same is for MyServletA as i followed the same instructions - so MyServletA\WEB-INF\src\nl\hello

Thanks and sorry about this I am quite new to servlets so don't really know what i am doing.
1 week ago
Yes so locating to http://localhost:8080/MyServletA/ does work - shows what i expect see the screenshot attached:

but when i click the link it just takes me to http 404 see attached

1 week ago
All i am trying to do is open up the test.html which only contains this code plus a " <a href="file:///C:/Users/REMOVED/Documents/Project/HelloWorld/WEB-INF/src/nl/hello/MyServletA">This is an amazing servlet.</a>  " so in my mind when i click on that link it should just return message which contains 'If you're reading this, it worked!" as per below code in MyServletA.java




when i click on the link it says

ms-appx-web://microsoft.microsoftedge/assets/errorpages/dnserror.html?ErrorStatus=0x800C0005#file:///C:/Program%20Files/Java/apache-tomcat-9.0.14/webapps/MyServletA/WEB-INF/src/nl/MyServletA

if i type in

file:///C:/Program%20Files/Java/apache-tomcat-9.0.14/webapps/MyServletA/WEB-INF/src/nl/

in my web browser it takes me to that location where MyServletA.java is.

I feel like what I'm trying to do is more simple than the example in the guide mentioned above.

The .war file should be structured the same as the example for HelloWorld, i did this as i thought it as i thought it would be more likely to work.
1 week ago
Sorry didn't seem to paste the html correctly

<a href="file:///C:/Users//Documents/Project/HelloWorld/WEB-INF/src/nl/hello/MyServletA">
2 weeks ago

Frits Walraven wrote:Please post your html file, your web.xml file, and the contents of your war file.



This is my web.xml



This is my test html

<HTML>
<BODY>    
<a href="file:///C:/Users//Documents/Project/HelloWorld/WEB-INF/src/nl/hello/MyServletA">This is an amazing servlet.</a>  
</BODY>
</HTML>

I removed the user account


How do I post the contents of the .war file as if I was to open it in notepad ++ it's not really readable.

2 weeks ago

Paul Clapham wrote:The code you posted suggests that MyServletA isn't in a named package. You can't use servlets in the default package, so perhaps you need to fix that.



I put it in the same package as the example about tomcat, followed the instructions that i thought were relevant in there. So the code is now:




compiled it from the src directory

javac nl\hello\MyServletA.java –d ..\classes

I adjusted the webconfig file slightly and also created a .war file.

Changed my test.html to point to the new location of MyServletA.java

ran startup.bat

Still same issue.
2 weeks ago

Frits Walraven wrote:You might want to look at this small tutorial, it is old but still usable: HowToCreateWebApplicationWithoutAnIDE



Whilst that tutorial was good, it still did not solve my issue with opening my url which is pointing to MyServletA.java

Do you know how I can resolve this?

When i click the link in 'this is an amazing servlet' it does not open the java text in the message variable, it just says can't reach this page, yet when I type in MyServlet.java it will display all of the java code
2 weeks ago
Ok so,

I downloaded new version of Java and removed JRE_HOME

Updated JAVA_HOME and (personal) PATH variable to include the new version of java.

so now these are my variables:

PATH - PATH: .;C:\Program Files\Java\apache-tomcat-9.0.14\bin;C:\Program Files\Java\jdk-11.0.2\bin
JAVA_HOME - C:\Program Files\Java\jdk-11.0.2
CATALINA_HOME - C:\Program Files\Java\apache-tomcat-9.0.14

Now startup works -

I have to run cmd as an administrator.

Thanks for your help, I'm assuming it was the version of Java I had previously was too old for the version of tomcat?
2 weeks ago
ok so i went to this location - C:\Program Files\Java\apache-tomcat-9.0.14\bin

typed cmd in the address bar which open cmd in that location

typed set PATH=%PATH%;%JAVA_HOME%\bin;%CATALINA_HOME%\bin

all it does is return a new line

then I type startup and same error

The JRE_HOME environment variable is not defined correctly
This environment variable is needed to run this program

Really don't know what to do
2 weeks ago

Nicholas Evans wrote:OK well i ran that command and it didn't change my path, i'm assuming you mean system variables path - when i checked it wasn't updated and there is several things for that variable - see here

C:\Program Files (x86)\Common Files\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;%SYSTEMROOT%\System32\OpenSSH\;



Also i have now added that path to path system variables but still having same issue.
2 weeks ago
OK well i ran that command and it didn't change my path, i'm assuming you mean system variables path - when i checked it wasn't updated and there is several things for that variable - see here

C:\Program Files (x86)\Common Files\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;%SYSTEMROOT%\System32\OpenSSH\;
2 weeks ago

Frits Walraven wrote:ok, the CLASSPATH is wrong.

Update your PATH from a cmd window like this:



Sorry you say CLASSPATH is wrong s do i want to change that or PATH?
2 weeks ago

Frits Walraven wrote:what does java -version in a cmd window give you as a result?

You don't need JRE_HOME.

CATALINA_HOME is tomcat's home directory.





Hello,

Please see my version below.


java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)


There is an entry in program files (x86), tried both for JAVA_HOME and still doesn't seem to work.
2 weeks ago