I'm creating a project with Struts2. I personally use jsp for web-side. I personally use MySQL database for my application and that i installed wamp server for this. My web addresses are just like localhost/xxx?title.action?blablabla... rather than i wanna redirect web addresses. For exampleinstead of title.action on my small url I wanna use localhost/title or something like that like this. Also with .htaccess I wanna send data regarding this as like title.action?Id=$1... for my action at struts side. However could not redirect the web addresses, I could not define document root correctly and .htaccess file. What must i do, are you able to explain it step-by-step?
Your configuration will rely on what brand Java EE server you will use. Apache Tomcat has an excellent AJP integration with Apache webserver so that’s what I'll be using within this example configuration.
You are writing that you'd like to complete URL remapping in Apache. I strongly advice against it, as this makes it very difficult to dynamically generate you’re URL inside your application. You are able to better make use of the URL mapping options that come with your internet framework to be able to keep link producing support of this framework.
I’m unfamiliar with Struts, but when it doesn't support this fundamental feature I would suggest you change to the Stripes framework or even the more complicated Spring MVC framework. You further write you need to use JSP, and so i also recommend you apply the MVC pattern each one of these framework support. Which means you map URL's to action/controller objects rather than straight to JSP files.
Below is definitely an example .htaccess configuration which will pass all incoming URL's that finish on
.action for your Java EE server. The URL's are passed through exactly like the asked for URL including their (optional) parameters. Make certain that port 8009 may be the AJP listener port of the Java EE server (otherwise change it out towards the port you've set up).
# Example .htaccess # # Please make sure 8009 is the port number of your Java EE server RewriteEngine On RewriteBase / RewriteRule ^(.*\.action)$ ajp://127.0.0.1:8009/$1 [P,QSA,L]
Also make certain you've set up Apache properly. For instance you must have set up the right modules, fundamental essentials ones I've enabled (although you will possibly not need all them):
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_ajp_module modules/mod_proxy_ajp.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule rewrite_module modules/mod_rewrite.so
If utilizing a current version of struts2, 2.2.1 you need to setup the application according to: http://struts.apache.org/2.2.1/docs/create-struts-2-web-application-using-maven-to-manage-artifacts-and-to-build-the-application.html please search the page for "web.xml Servlet Filter" once this is accomplished "title" and "title.action" are generally valid mappings towards the "title" action. For url parameters this really is instantly taken proper care of with struts form tags. The fundamental lessons and tag reference good examples around the struts.apache.org site. Document root is generally setup via IDE from project title, further whenever you compile often the IDE can create a WAR, when implementing the WAR using a web interface for the application server / web container altering the document root is generally among the visible fields throughout installation. To ensure that is definitely configurable on the per installation basis.
You don't have to make use of the .action extension in Struts2. You are able to choose a different extension or no extension (so it seems like is what you would like).