2

I have a java web application created in NetBeans from 'File-->New Project-->Java Web-->Web Application'.
I have Tomcat as the server. In my computer I can run php without any problem in a NetBeans php project, or in XAMPP.
But I want to run php commands in a java web application project. I tried by adding this code to index.jsp file

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <?php echo 'php code here'; ?>
        <h1>Hello World!</h1>
    </body>
</html>  

It doesn't print 'php code here' string but print 'Hello World!' string.
I tried renaming file name index.jsp to index.php (And also change the name in web.xml file). But it still gives me the same output

Can anyone please tell me how to do this?

4
  • Use <?php ?> tags instead of <? ?> tags. The parser may be confused. Commented Aug 9, 2012 at 13:13
  • And make sure your server is set up to interpret .jsp pages as "may contain PHP code". Commented Aug 9, 2012 at 13:14
  • sorry it was a mistake. It is <?php ?>.I changed it.but same result. What do you mean by "And make sure your server is set up to interpret .jsp pages as "may contain PHP code" Commented Aug 9, 2012 at 13:18
  • please tell me how to do that? Commented Aug 9, 2012 at 13:19

1 Answer 1

1

Check your Apache configuration (httpd.conf). On the line that contains "AddType application/x-httpd-php .php", add .jsp to the end

AddType application/x-httpd-php .php .jsp

And whatever other pages you want to be interpreted using PHP (.html, .htm, etc.).

Sign up to request clarification or add additional context in comments.

14 Comments

it still doesn't work. There wasn't "AddType application/x-httpd-php .php" in my httpd.conf file. I added it as "AddType application/x-httpd-php .php .jsp". then restart the server. but still doesn't work
@Roshanck Is php installed on your machine?
I think so. I can run php netbeans projects.I can run .php files in XAMPP server. that means I have php installed in my machine right? :)
What happens when you navigate to a locally hosted php page in your browser?
It display the output. As a example if i have a file name index.php and <?php echo 'php code here'; ?> inside the index.php file. When I navigate to localhost/index.php file, it display 'php code here' as the output
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.