这是我的Spring安全豆
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<http auto-config="true">
<intercept-url pattern="/welcome*" access="ROLE_USER" />
<form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="username" password="123456" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
这是我的MVC-dispatcher servlet
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<mvc:annotation-driven />
<tx:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.apsas" />
<!-- Required for body marshalling -->
<mvc:resources mapping="resources/**" location="/WEB-INF/resources/" />
<bean id="entityManager"
class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="apsaspu" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
</beans>
这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-dispatcher-servlet.xml,
/WEB-INF/spring-security.xml</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
@Controller
@RequestMapping(value = "/c")
public class MainController {
@RequestMapping(value = "/welcome", method = RequestMethod.GET)
public String printWelcome(ModelMap model, Principal principal) {
String name = principal.getName();
model.addAttribute("username", name);
model.addAttribute("message", "Spring Security Custom Form example");
return "hello";
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(ModelMap model) {
return "login";
}
@RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
public String loginerror(ModelMap model) {
model.addAttribute("error", "true");
return "login";
}
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(ModelMap model) {
return "login";
}
}
HTTP ERROR 500
Server Error
java.lang.NullPointerException
at com.apsas.controller.MainController.printWelcome(MainController.java:30)
默认的spring security登录页面是[application context]/j_spring_security_check
您的登录页面将提交给/apsas/c/j_spring_security_check
。假设您的应用程序上下文是apsas
,您的登录表单应该提交给/apsas/j_spring_security_check
或./j_spring_security_check
。
明确地说,这是登录页面上form
元素的action
属性的值。如果您需要帮助,张贴您的登录页面到问题,我可以更具体。
这是我的代码。我不知道这有什么问题。
问题内容: 我已经检查了关于stackoverflow的几乎所有相关文章,但是我无法解决我的问题。 Here is the code: web.xml: spring-servlet.xml: myController: Web Pages/index.jsp: Web Pages/WEB-INF/jsp/hello.jsp: 因此,当我启动该应用程序时,index.jsp已正确加载,但是当我单击
早上,我已经检查了这个问题的大部分答案(在名为DispatcherServlet的DispatcherServlet中找不到URI为的HTTP请求的映射),以及(在名为“DispatcherServlet”的DispatcherServlet中找不到URI为[/ChickenTest/index]的HTTP请求的映射),但我仍然得到“在名为“bmoa”的DispatcherServlet中找不到U
我已经查阅了几乎所有关于stackoverflow的相关文章,但我就是不能解决我的问题。 下面是代码:web.xml: spring servlet。xml: myController: 网页/index.jsp: 网页/WEB-INF/jsp/hello.jsp: 所以当我启动应用程序时,索引。jsp加载正确,但当我点击href导航到hello时。jsp我收到一个404错误,服务器日志显示: 我
我的web.xml applicationContext as 调度器servlet作为 与包com中相同的控制器。思维边缘。特斯塔普 当我点击. 警告:在带名称的DispatcherServlet中找不到与URI[/TestApp/samp]的HTTP请求的映射 此外,当Spring开始时,我没有看到Testapp/示例加载的处理程序 我猜我的组件扫描不起作用。为什么?还有其他原因吗 编辑:调度
当我在JBoss上启动项目时,在名为“appServlet”的DispatcherServlet中,找不到URI为[/myappname/]的HTTP请求的映射。在将访问方法更改为会话后,在解决此处描述的另一个问题:“未找到当前线程的会话”后出现了此问题 在一切顺利之前。我使用的是ApacheTiles 2。我读了一些类似的问题,但我找不到有效的解决方案。 这是我的没有HiberNate配置的文件