does mvc architecture affect SEO? - java

I have my MVC architecture in my webapplication.Now the flow is as follows:
starter.jsp -> SERVLET ->view.jsp
Now view.jsp expects cetrtain request parameters to be present in request object.
When view.jsp is called using above workflow everything works fine.But if view.jsp is called directly then it does not get expected attributes in request and forwards to error.jsp
Now Will search engine directly call view.jsp? or will it travel from starter.jsp to view.jsp?
Detailed example:
main page has a href to a article.
href ="servlet?id=xyz"
Now servlet gets the id from request.
Servlet gets details for id from DB , puts the Object obtained from DB as request attribute
idDetails
And forwards to view.jsp
View.jsp gets request attribute idDetails
So view.jsp expects idDetails to be present as request attribute

There is no correlation between SEO and MVC. MVC manages the internals of your application while SEO is some external tweak. If they correlate somehow then there is something wrong with your application in my opinion.
If some files are public so the search engine can see them it is likely that they will be indexed. If in doubt you can always check your pages in google for example using the site: prefix.
So the point is that if you can see it google can see it.

I agree with Adam's reply. SEO and MVC architecture are not related at all.
If you have fear like, what happen If "CRAWLERS" will directly access your view.jsp page, then I suggest you to use Filters and Interceptors in your application.
So here your interceptor/filter will intercept the incoming request and filter it out if they are directly made by "Crawler Algorithm" OR "Suspect User".

Related

Spring Controller "redirect"

I'm been search for a solution for this problem for a while and didn't found any!!
To explain the problem I will give and example:
Let's imagine that I have a search page X with results (x1....x10) and a form to give feedback. This form will call a link for a controller (java spring controller) defined as '/feedback.html'. After the submit the feedback, the controller should return again to X with the same results. And here is the problem, how can I do this? because this feedback controller can go to X or to any other page depending where the form is!
In summary: How can I do the javascript history(-1) in the controller (java spring controller)??
Thanks
If you access the search page like this:
http://domain.com/search/query
or
http://domain.com/search?query=text
Then you can just pass this ulr along with the feedback form (by adding a hidden input with its value the URL)
<% request.setAttribute("redirectURL",
request.getAttribute("javax.servlet.forward.request_uri"));%>
<form:hidden path="redirectURL" value="${redirectURL}"/>
And then in the controller simply access the redirectURL property and redirect to the search page with the same query showing the same results.
The "redirect" Spring capabilities is usually used within a PRG pattern. Given your title and your use case, I'll assume you're trying to get redirected to the search page or another page after submitting your form (form action seems to be '/feedback.html').
So basically you have your feedback controller which should have a #RequestMapping annotated method like #RequestMapping(value = "/feedback.html", method = RequestMethod.POST). From there and within this method, you can redirect the request anywhere you want by returning a String matching an existing mapping in you Spring app (for example, if you want to redirect to the search page, given your search page is mapped with #RequestMapping(value = "/search.html", method = RequestMethod.GET), simply return "redirect:/search.html".
Note that the whole "search page" logic will have to be re-run (the redirect issuing a new GET request) so if you don't want that to happen, you will indeed have to store the search results in session (not sure what sense does that make... but it's possible).
EDIT : If your URL mapping permits it, you can also redirect the request to the search page with search parameters included, something like : "redirect:/search.html?myParam=10".
I think, in the search controller, you can store X in session and at the end of your feedback controler send a redirect to an URL that call the search controller (same methode or another one) that load the search result page using the X held in session.
You can also pass the X parameter with hiden field (if you dont want to use session).

How servlet handle multiple request from same jsp page

Sorry friends if this question is very easy but i am confuse i unable to find out solution.
As we all know in spring MVC framework we create controller which will handle multiple request from same page using #requestmapping annotation.
but same thing i want to do in servlet how can i do ?
Suppose i have a jsp which which will contain a jqgrid,and two forms i want to use only one servlet to load the data into jqgrid and that servlet only will handle request from both the form . Since we have only doGet and doPost in servlet how one servlet fulfill all three request. Hope you understand my question if you have and link where i get sample or and tutorial link plz reply me
Well, the only easy way to do this would be to use a request parameter to control how the processing happens.
In a very basic example, you may have something like a requestType value that gets passed as either part of the query string or the request body. You would assign values of 1-3 (or 0-2) with each value indicating a different type of request. Your servlet would then parse the request accordingly.
This actually is how the DispatcherServlet in SpringMVC works. There's only one servlet class instance and when a request comes in, it examines the query string along with other parts of the request to determine which controller should handle the request.

passing values between servlet and java file

I've one spring controller which is setting some values to request and shows a jsp page. For the view part we use tiles. The result page has 3 parts, header , content and footer jsp's.
This header jsp use a java file and i want to access the attributes created by the first spring controller from this file. Is there any way to do that without using session?
When I tried request.getAttribute, it gives null. I think it's because it's not an immediate file after the request values setting.
As long as everything runs in the same request and the controller code is executed before the view part, setAttribute() should work. To debug issues like that, use a Filter which dumps the request URL and attributes to the console or the log.
If those calls are in different requests, you have two options: The session and a Spring bean (use a session bean or your own implementation). I prefer beans since they are type safe and they allow me to separate my code from the Servlet API which is complex to test.
You'll really need to put some code to get a code answer but unless you're using JSP scriptlets I'm guessing this is a Java bean that you're using in the header. This of course cannot access the request (hence the session) nor should it really. What you probably want to do is convert it to a tag library if you want it to have access to the request/session.

How to redirect all new user requests to front page in Spring MVC?

I want to secure (temporarily) my application by create front page with captcha and simple form. I suppose Spring Security is too complicated for this task. How can I catch all requests and check if some attribute in session is set? If it is set then all these #RequestMapping methods should be executed, otherwise redirect to one front page.
Have a handler interceptor defined and applied to all the handlers. The example in that link shows you also how to perform the redirect. Also check the mvc:interceptors for the Spring 3 - like configuration.
You can simply configure a Filter for this

JSF Servlet Arch Help needed

i want a mechanism in my web app as described below:
user will enter mydomain.com/CompanyName , depending upon the CompanyNameit will show its logo and its customized page, and i will take that parsed parameter in session again upon each request i will compare the parsed CompanyName and one stored in session , and if they matched then application will show the requested page with user's data.else it will be redirected to login page.
and the main thing is i want this thing in JSF arch.
i tried taking a servlet that will resolve all request and it will parse and then will dispatch the request to prefered servlet,but problem is it goes in loop as again it resolves to the same controller servlet,
You can do this via a phase listener. You can define a global one in faces-config.xml (or using annotations, if JSF 2.0 is used)
<lifecycle>
<phase-listener>com.yourcompany.CompanyPhaseListener</phase-listener>
</lifecycle>
There you have access to the FacesContext, from which you can obtain the current request URI. Parse it and store the appropriate attributes in the request, which you can later read on your pages.
The phase listener is executed on the specified phase(s), and perhaps you should choose RENDER_RESPONSE
For affecting the way your URLs appear in the browser, check PrettyFaces.
i tried taking a servlet that will resolve all request and it will parse and then will dispatch the request to prefered servlet,but problem is it goes in loop as again it resolves to the same controller servlet,
Use a Filter instead. It by default doesn't listen on forwarded requests, so you won't get an infinite loop on forwarding.

Categories