Is is safe to edit the jsp in a .WAR file - java

I need to edit a jsp in a .WAR file to correct a spelling error. Is it safe to do so? Or does the war file have some magical setup that is broken as soon as I change anything?
I've read some on various forums about it and it seems ok, but it would be nice with confirmation from someone who knows.

I personally wouldn't edit a jsp inside a deployed war file. I would prefer to edit the jsp on my development machine, possibly test it, rebuild the war file with the updated jsp, and redeploy it on the application server.

it should be okay to edit the jsp in the .war, provided you also make the same edit in the original jsp, else you would lose the change when you re-create the war file (i presume your source code is checked into some repository)

Related

How to update Tomcat Web application?

I have an application, that is deployed to Tomcat as war file. I need to be able to update some resources of that application, like files with configurations, maybe classes and stuff.
If I understand correctly, if I replace those files within the directory, to which Tomcat extrcted war, at the next start up they wil be rewritten with contents of my war file. Maybe, I got this wrong?
I thought about deleting war prior to the update, but that seems like a stupid way to go.
Any suggestions are appreciated.
Update
I read here: https://tomcat.apache.org/tomcat-8.0-doc/deployer-howto.html#Deploying_on_a_running_Tomcat_server that the war overwrites the directory when it's "newer". What does that mean? What does Tomcat compare, Date Modified or Date Created or smth else?
For the sake of reproducible and stable builds -- don't. Either re-release your app or store config outside of webapp base.

HTTP 404 when trying to run a jsp file in eclipse

I get 404 error when trying to run a jsp file eclipse. The confusing thing is the server is running and I can go to localhost:8080 without any problems. I have attached an image of my configuration of server, the jsp file and also the location of the file and the error.
I embed the image cause of the reputation thing so I have linked it
More information:
I am using TOMCAT 7, ECLIPSE KEPLER I have checked the location of helloworld.jsp its in WebContent. I have restarted the server. I have created another dynamic web project nothing works. I get the same problem I can go to localhost:8080 but I cant run an JSP file
SOLVED:
Okay guys its pretty simple to solve this problem. There are two things you need to try.
1)Right click your project and export the war file into C:\ProgramFiles\Tomcat7 folder
If this does not work then.
2) Right click your project and export the war file into some directory and copy the war file into C:\ProgramFiles\Tomcat7 then start the Tomcat server and there you go your JSP file work.
You will probably end up doing step 2 because of stupid windows file permissions
Also thanks for all the help guys really appreciate it.
Make sure that u have put your Jsp files into the WebRoot and check the location and even check your Web.xml and after that run and still if its not working then post your Web.xml here.
Unfortunately, user3135774's solution does not work for me, as am using an Apple computer.
I have read and researched another problem (Error 500: No Output Folder), which I have along with Error 404, carefully, and I think this is related to permission issues.
The JSP file is supposed to be compiled and then deployed under Tomcat/work/Catalina/localhost/YourProjectName. The 404 error message means that there is no files in that directory. Since Eclipse has no write permission to this directory, you have to change the access permissions. After changing the permission to 777, there we have the compiled .java and .class files.
Since you do not have any of them
index.html/index.htm/index.jsp/default.html/default.htm/default.jsp page
To run your jsp page :
In Eclipse:
=>goto Java Resource
=>right click on your jsp page
=>in that select Run as Server.
After applying everythings, it did not work for me to read image file in eclips.
Finally, It works! after that I change deploy path.
Server Locations>Deploy path(Set with "Workspace" of Eclipse)

Installing a game on Tomcat. Newb here

this might be a tall order or it might be ridiculously simple. I wanted to run this game on my website: https://github.com/ajanata/PretendYoureXyzzy
Unfortunately I have no clue how to make something like this work. There didn't seem to be an installation file, so I can only imagine it's painfully obvious to anyone familiar with this sort of thing. I recently ordered a trial of a shared Tomcat server, since I'm assuming that's needed to run all the Java goodies.
If there are any simple instructions I should follow to install this, it would be much appreciated if you could share them!
You need to download the source from the Github link you provided and then download Eclipse - Java EE. You then open Eclipse and choose File->Import->General->Existing Projects Into Workspace and choose the folder you just downloaded. You can then choose Export->Web->WAR file and export the WAR file.
You then download and setup Tomcat as described here (ignore the parts after Tomcat is running and you can access it at http://localhost:8080) and install the WAR as described here.
If you are feeling exceptionally lazy I have built the war here. You just need to drop it into the webapps folder in your Tomcat installation and then restart your server. You can then access it at:
http://localhost:8080/cah.
Hard to say without looking deeper into the project, if they create a .war file somehow, just copy the .war file into [tomcat home]/webapps directory and your application will be deployed. You can then acces it at yourmachine:8080/warname
where warname == the name of the war file without the .war extension.
There appears to be a SQL script with the project as well, not sure if there is some database you might need to setup which could get tricky.

Can you pick up the source from a tomcat-deployed application?

Can you extract source from tomcat application? The webapp is not deployed as a .war file, it's a bunch of directories, xmls, configurations, .class files, .jars and stuff.
Your comments to Paul Tomblin indicate you already have access to the server. As he said, if you didn't upload the source to start with (which is normal), you can't get it off the server. However, there are a couple of things to note:
Unless you compiled your JSPs prior to uploading, they will contain their own source code and you can download them for use in another project or whatever it is you're trying to do
If you're desperate, you can decompile the .class files using something like JD (http://java.decompiler.free.fr). The decompiled code will not include comments and is not always spot-on, but it will get you much further than you are now.
You don't have to put the source code on your web server, just the compiled class files. So no, if the source isn't on the server, nobody can "pick it up". In a normal configuration, I don't think it's possible even to download the individual class files, but it might be possible if you put your Tomcat webapps directory somewhere where your normal web server (Apache) can find them.

Some Tomcat webapps not opening

I downloaded a couple of webapps and placed them in my /webapps folder.
Some of them I could open by going to http://localhost:8080/app1 and it would open.
However, some others I would do the exact same thing and go to http://localhost:8080/app2 and it will display "HTTP Status 404 - /app2/", even though I am sure it is there. I've checked that it contains a WEB-INF folder just like app1, and I've even restarted Tomcat to be sure.
My question is: is there anything (perhaps in the web.xml file) that specifies what the URL has to be to start the webapp? Or is it simply just http://localhost:8080/<folder name> ?
P.S. If you want to know exactly what app1 and app2 I am refering to:
app1 (works) = http://assets.devx.com/sourcecode/11237.zip
app2 (doesn't work) = http://www.laliluna.de/download/eclipse-spring-jdbc-tutorial.zip
I've tried a few others as well, some work, some don't. I'm just wondering if I'm missing something.
I usually debug this by going the the manager page and making sure that all of the contexts are deployed (http://localhost:8080/manager/html).
It sounds like app2 has not been deployed properly or is not starting up because of some other error.
I would look at the logs. There may be a bunch of information in there but usually it explains what is broken.
The second app (the directory named WebRoot) can also be deployed correctly but you get a 404 by going to it because there is not an "index.jsp" or "index.html" file in the root directory.
Try putting a file there with any of those names, and the 404 is gone.
A servlet mapping in the web.xml is not strictly necessary for this to work.
The first zip file you mention has a .war file as part of the zip. The second one is just the source code and it needs to be built into a .war file.
It looks like it is setup to have that done in Eclipse. Try the File>>Export option and select War file as the export type.
The second requires the spring framework. The only runnable things I could find were a client in eclipse-spring-jdbc-tutorial.zip\SpringJdbc\src\test\de\laliluna\library\TestClient.java and one in eclipse-spring-jdbc-tutorial.zip\SpringJdbc\src\de\laliluna\library\sample\MyApplication.java. If you open it in eclipse (it is an eclipse project), and compile, provided the Spring framework is installed, you should be able to run both.
Are you familiar with log4j? Spring puts a lot of often-useful information into the logs created via log4j. When I have a SpringMVC application that won't startup correctly or otherwise isn't running I check my log4j and potentially turn up the Spring log level to INFO or even DEBUG.
If "/" is not accessible it means that there is no "index.html", "index.jsp" or whatever is defined in the welcome-files list of the web.xml
Also no Servlet-Mapping for the context ROOT directory is present.
Check the web.xml for Servlet-Mappings or try to figure out the name of the jsp/html /... file being in the context root

Categories

Resources