954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Configuring Apache Tomcat to allow PHP as well?

Hey

How do I make Apache Tomcat allow to interpret PHP as well?

Allowing something like:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><meta http-equiv='pragma' content='no-cache' /><title>Hello</title></head><body>");
out.println("<?php echo 'Hello'; ?>");
out.println("</body></html>");
out.flush();
out.close();
}


Thanks!

riahc3
Posting Pro
545 posts since May 2008
Reputation Points: 50
Solved Threads: 2
 

You need to have Tomcat to run on top of Apache 2 for start. However obvious question coming to my mind, what are you trying to do with this old fashion page building process????

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

My (idea) is

Login (HTML)
PHP validates it querying a BD and returns view products
Select a product and using data from the login and product selected, passes to my Java servlet to produce a file....


Basically thats the line more or less. Dont take that word for word though...

riahc3
Posting Pro
545 posts since May 2008
Reputation Points: 50
Solved Threads: 2
 

OK, I will call you crazy. There is no reason to do such stuff when Java is able to handle all this. Simple example can be found here in JSP section or if you willing to learn there is number of frameworks that can help you with database management like Hibernate, with website like Wicket

PS: Post is moved to JSP section

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

OK, I will call you crazy. There is no reason to do such stuff when Java is able to handle all this. Simple example can be found here in JSP section or if you willing to learn there is number of frameworks that can help you with database management like Hibernate, with website like Wicket

PS: Post is moved to JSP section


Go ahead, call me crazy :P

No, but seriously, Im doing this in PHP as I see making a servlet for this is a overkill and simply using a PHP script I can do it alot faster and easier.

riahc3
Posting Pro
545 posts since May 2008
Reputation Points: 50
Solved Threads: 2
 

Well then once you logged in on PHP side and have all data you may want to create request POST (attach all data you need to this request) on which servlet is specifically listening. Servlet will then retrieve data from request and do what ever it has to do. However that mean keeping bot technologies separated and communicate through request unlike you above attempt. Above is just theory, I did very little with PHP at university long time ago so I wouldn't be able to advice.

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

Ive been told today that I cant run a AMP server (to interprete PHP for example) and Java servlet on the same location.

riahc3
Posting Pro
545 posts since May 2008
Reputation Points: 50
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You