Hello, I am working on spring mvc and I have in my home page a a simple link of page register and the register.jsp is contained in my WEB-INF/pages/register.jsp
So on my index.jsp which is in my base folder means in webcontent parllel to WEB-INF so how can i link this register.jsp
<li class="float-block" style="margin-left:50px;"><a href="pages/register.jsp" class="login" title="New User Register here" >Register</a></li>
Please suggest me how to do this to run this link
You can do that by redirecting it to a controller and then to the jsp of your need.
Check this link.
It depends on your configuration. Check request mapping in your controller class and all xml configurations.
Normally it should be something like <a href="/register"> depends on the controller.
a href tag name and request mapping of controller class address should be same and add the object of that class in Form Tag like
Related
I am a web designer but I am told to design static pages in mvc where rather then using href="some url" I have to use href="#Url.Action("Controller", View)" Now I want to pass a section id in the url so when the user redirects it will be scrolled down to that specific section usually in html this is the syntax I use
href="index.html#mysectionid"
in Html I have something Like this
<section id="mysection">
</section>
I want to Know How I am gonna do this thing in mvc. Thanks
You can mix C# code with normal html in Razor:
Test
I have used template/login.html for logging in, after successful logged in how to redirect the login.html page to chatwindow.html page (some other html) in Django framework.
So, do I need to redirect it from views.py file or from login.html?
Any help highly appreciated.
Django implements multiple ways to do this:
1. LOGIN_REDIRECT_URL
This is a global setting in your settings.py. It works for all login pages when next= parameter is not specified in login url (e.g. example.com/login?next=/foo).
2. Use next parameter in the login URL
This is usually used to customize the login redirect for individual cases.
The common use-case is when you use #login_required decorator. When a user tries to access a page which requires authentication, a user is then redirected to a login page with a next= parameter pointing to the current page. For example if the user went to /secure/page, then the login page will be something like /login?next=/secure/page. After the user will successfully authenticate, Django will redirect them back to the protected page.
3. Use the hidden input next on the login page
Finally you can set the redirect path in the login form itself:
<form method="POST" ...>
<input typy="hidden" name="next" value="/secure/page">
...
</form>
I would guess that first method might be the most appropriate in your case however keep in mind the other options if you will need them.
I am implementing an html template for a Contact us page in my app. I am wondering if I can somehow pass a link for that page, which will have no behaviour, without having to generate a new controller which seems to be not possible. I tried to place the template in the public folder and then pass a link to /public/contact, being the template contact.html.erb, but rails returns a uninitialised controller routing error.
here is what I have set in the routes.rb file
get 'public/contact'
and this is the application.html.erb that carries my link to that
</div>
<ul>
<li>HOME</li>
<li>NEWS</li>
<li>FAQ</li>
<li>CONTACT US</li>
</ul>
Notice that we have also the path info/news and info/faq
I had generated a controller info to handle all these static pages. I would just like to know if this a good practice or should I use other drier way to implement this?
It is actually a good approach to have a controller for your static pages as well, you can actually generate a controller for pages to handle the static pages like about, contact e.t.c rails generate controller pages contact about
you would just access that in
localhost:3000/pages/contact
Then your view would be in app/views/pages/contact.html.erb
routes.rb
get "pages/contact"
get "pages/about"
wHY do you need to generate a new controller just for a request.Recommended way is to just add a new action in your common/utility controller with a get request to show about us.
for example: match '/about' => 'pages#about'
This is good as you can cache the page to boost performance as well you can make it dynamic(html.erb)
OR
Assuming that the static file(only html) is in public folder,ADD an anchor tag directly to open it in new page using target=_blank attribute.
<%= link_to "About Us", "/about_us.html" ,:target=>"_blank"%>
I have a MVC4 application and have hosted on IIS8.5 with published file.
I have a link on my cshtml page
<a href='/home/ContactGrabber'>Import Contacts</a>
Here home is controller and ContactGrabber is an action of controller. When I am clicking on this link it show 404 error because url is showing
http://localhost/home/ContactGrabber
It should be
http://localhost/cruuntest/home/ContactGrabber
But when I am running my development code without hosting on IIS. it works fine.
Can anybody help me on this?
Use Url.Action helper for this, so that your url is generated right, by this way you wull face issues:
<a href='#Url.Action("ContactGrabber","home")'>Import Contacts</a>
you can see details of it on MSDN
http://msdn.microsoft.com/en-us/library/dd505232%28v=vs.118%29.aspx
You can also use Html.ActionLink to generate the anchor tag:
Razor:
Html.ActionLink("Import Contacts",
"ContactGrabber", // <-- ActionMethod
"home", // <-- Controller Name.
null, // <-- Route arguments.
null // <-- htmlArguments .. which are none.
)
MSDN docs
I have a very simple JSP page first.jsp that gives reference to so many other JSP pages through hyperlink.
I am trying to pass a value through the hyperlink in first.jsp and retrieve it in second.jsp using request.getparameter().
I used:
Second JSP
and in the second.jsp page I used:
alert( "value = " + <%= request.getParameter("value") %>);
but when I try to run the code and click on Second JSP I get a 404 page not found error for:second.jsp?value=1
It looks like your URL to second JSP might not be good. "second.jsp" is not visible to your web app server the way you specified.
To fix this:
If your jsps are resolved through a web app try:
Second JSP
if you have jsp or similar directory that is visible outside of web app context do something like:
Second JSP
Try getQueryString() method to access the value that you passed through the URL.
Then use string methods to extract the value form the URL.
For example, you pass the parameter as you mentioned
Use getQueryString() method in second.jsp, it will return the string value = 1 as the result.
Html:
<a href="birth1.jsp?key=14APR010315381">
<center>
<font size="2" color="black">MIKE LOBO</font></center>
</a>
Jsp:
request.getParameter("key");
I m using in my project and its working fine