Эй, я совершенно не понимаю, как работает ajax uri.Пожалуйста, посмотрите на код ниже:
<script>
function clickHandler(){
$.ajax({
**url : "http://localhost:8080/csp/ajaxchangerole.html?user=" + document.getElementById('userid').value,**
dataType: 'text',
success : function (data) {
$("#roleval").html(data);
}
});
}
Это также работает, даже если я изменяю URL таким образом
<script>
function clickHandler(){
$.ajax({
**url : "ajaxchangerole.html?user=" + document.getElementById('userid').value,**
dataType: 'text',
success : function (data) {
$("#roleval").html(data);
}
});
}
Ноесли я изменю URL на любой из двух URL, упомянутых ниже, он даже не вызовет контроллер.Я не уверен почему.Может кто-нибудь объяснить, что мне нужно для вызова контроллера по нижеуказанным URL-адресам?
url: "admin / ajaxchangerole.html? User =" + document.getElementById ('userid'). Value, ИЛИ url: "http://localhost:8080/csp/admin/ajaxchangerole.html?user=" +document.getElementById ('userid'). value,
Вот мой фрагмент из моего XML-файла, в котором есть сопоставления для вышеуказанных URL:
<bean name="/admin/changerole.html" class="csp.spring.controller.admin.ChangeRoleFormController" >
<property name="customerDao" ref="customerDao" />
<property name="commandName" value="customer" />
<property name="commandClass" value="csp.model.Customer" />
<property name="formView" value="admin/changerole" />
<property name="successView" value="home" />
</bean>
<bean name="/admin/ajaxchangerole.html"
class="csp.spring.controller.admin.ChangeRoleAjaxController">
<property name="customerDao" ref="customerDao" />
<property name="authorityDao" ref="authorityDao" />
</bean>
Я не могуПонимаю, почему я должен удалить "/ admin" из двух приведенных выше сопоставлений, чтобы заставить эту часть Ajax работать. Любая помощь очень ценится. Заранее спасибо.
С уважением, Серотонин Чейз
Fyi,мои контроллеры:
1.ChangeRoleAjaxController
package csp.spring.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import csp.model.Authority;
import csp.model.Customer;
import csp.model.dao.AuthorityDao;
import csp.model.dao.CustomerDao;
import csp.model.dao.ParkingLotDao;
public class ChangeRoleAjaxController implements Controller {
CustomerDao customerDao;
AuthorityDao authorityDao;
public CustomerDao getCustomerDao() {
return customerDao;
}
public void setCustomerDao(CustomerDao customerDao) {
this.customerDao = customerDao;
}
public AuthorityDao getAuthorityDao() {
return authorityDao;
}
public void setAuthorityDao(AuthorityDao authorityDao) {
this.authorityDao = authorityDao;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
System.out.println("Username: " + request.getParameter("user"));
Customer customer = customerDao.getUserByName(request.getParameter("user"));
Authority a = customer.getAuthority();
if(a.getAuthority().equals("ROLE_USER"))
a.setAuthority("ROLE_OWNER");
else if(a.getAuthority().equals("ROLE_OWNER"))
a.setAuthority("ROLE_USER");
authorityDao.add(a);
customer.setAuthority(a);
customerDao.add(customer);
return new ModelAndView("/admin/ajax_changerole").addObject("role", a.getAuthority());
}
}
Следующий контроллер: 2. ChangeRoleFormController
package csp.spring.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.providers.encoding.PasswordEncoder;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import csp.spring.security.SecurityUtils;
import csp.model.Authority;
import csp.model.Customer;
import csp.model.dao.AuthorityDao;
import csp.model.dao.CustomerDao;
public class ChangeRoleFormController extends SimpleFormController {
CustomerDao customerDao;
public CustomerDao getCustomerDao() {
return customerDao;
}
public void setCustomerDao(CustomerDao customerDao) {
this.customerDao = customerDao;
}
/*
protected Object formBackingObject( HttpServletRequest request )
throws Exception
{
return new Customer();
}*/
protected ModelAndView onSubmit( HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors ) throws Exception
{
Customer customer = customerDao.getUserByName(request.getParameter("user"));
String name = customer.getFirstName() + " " + customer.getLastName();
String username = customer.getUserName();
String role = customer.getAuthority().getAuthority();
return new ModelAndView("/changerole").addObject("name", name)
.addObject("username", username).addObject("role", role).addObject("flag", true);
}
}
Мои два файла jsp: 1. changerole.jsp 

Следующий файл jsp: 2. ajax_changerole.jsp
