81,095
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="UTF-8"?>
头不是这个吗?[/quote]
是的
全文搜下text/html;charset = UTF-8,看都正确的不[/quote]
我后来发现写了下面这个就报错。。。注释掉就是对的,不知道是什么问题
@ResponseBody
@RequestMapping("Login")
public String hasha1ss(String account,String psw,HttpServletRequest request,HttpServletResponse response){
HttpSession httpSession = request.getSession();
Users userEntity = userService.findByID(account);
if(userEntity == null) return "false";
else if(userEntity.getPwd().equals(MD5Util.MD5Psw(psw,userEntity.getPwd()))){
httpSession.setAttribute("account",userEntity.getUserid());
return "success";
}else {
return "false";
}
}
<?xml version="1.0" encoding="UTF-8"?>
头不是这个吗?[/quote]
是的
全文搜下text/html;charset = UTF-8,看都正确的不[/quote]
我后来发现写了下面这个就报错。。。注释掉就是对的,不知道是什么问题
@ResponseBody
@RequestMapping("Login")
public String hasha1ss(String account,String psw,HttpServletRequest request,HttpServletResponse response){
HttpSession httpSession = request.getSession();
Users userEntity = userService.findByID(account);
if(userEntity == null) return "false";
else if(userEntity.getPwd().equals(MD5Util.MD5Psw(psw,userEntity.getPwd()))){
httpSession.setAttribute("account",userEntity.getUserid());
return "success";
}else {
return "false";
}
}
[/quote]
整个MainController代码:
@Controller
@RequestMapping("/")
public class MainController {
@Autowired
UserServiceImpl userService;
@ResponseBody
@RequestMapping(value = "test",produces = "text/html;charset=UTF-8")
public String hahassddsas(String body, HttpServletRequest request, HttpServletResponse response) {
return "success";
}
@ResponseBody
@RequestMapping(value = "Login",produces = "text/html;charset=UTF-8")
public String hasha1ss(String account,String psw,HttpServletRequest request,HttpServletResponse response){
HttpSession httpSession = request.getSession();
Users userEntity = userService.findByID(account);
if(userEntity == null) return "false";
else if(userEntity.getPwd().equals(MD5Util.MD5Psw(psw,userEntity.getPwd()))){
httpSession.setAttribute("account",userEntity.getUserid());
return "success";
}else {
return "false";
}
}
}
上面的“test”map没有问题。。。但只要写了下面的就报错。。<?xml version="1.0" encoding="UTF-8"?>
头不是这个吗?[/quote]
是的
全文搜下text/html;charset = UTF-8,看都正确的不[/quote]
看过了没问题啊。。。<?xml version="1.0" encoding="UTF-8"?>
头不是这个吗?[/quote]
是的
全文搜下text/html;charset = UTF-8,看都正确的不<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
default-autowire="byName" default-lazy-init="true">
<!-- 启用spring mvc 注解 -->
<context:annotation-config />
<!-- 设置使用注解的类所在的jar包 -->
<context:component-scan base-package="com.gillian" />
<!-- 使用C3P0数据源,MySQL数据库 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<!-- MySQL5 -->
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test"></property>
<property name="user" value="root"></property>
<property name="password" value=""></property>
<property name="maxPoolSize" value="40"></property>
<property name="minPoolSize" value="1"></property>
<property name="initialPoolSize" value="1"></property>
<property name="maxIdleTime" value="20"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 依赖注入数据源,注入正是上面定义的dataSource -->
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources"><!-- mappingResouces属性用来列出全部映射文件 -->
<list><!-- 以下用来列出Hibernate映射文件 -->
<!--<value>com/centling/entity/UserEntity.hbm.xml</value>-->
<value>classpath:com/gillian/entity/UsersEntity.hbm.xml</value>
<value>classpath:com/gillian/entity/EmployeesEntity.hbm.xml</value>
</list>
</property>
<!-- 定义Hibernate的SessionFactory的属性 -->
<property name="hibernateProperties">
<props>
<!-- 指定数据库方言 -->
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLInnoDBDialect
</prop>
<!-- 是否根据需要每次自动创建数据库 -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
<!-- 显示Hibernate持久化操作所生成的SQL -->
<prop key="hibernate.show_sql">true</prop>
<!-- 将SQL脚本进行格式化后再输出 -->
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.connection.url">jdbc:mysql://localhost:3306</prop>
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
</props>
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true" version="3.0">
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Spring字符集过滤器 -->
<filter>
<filter-name>SpringEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SpringEncodingFilter</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 读取spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
spring-dispatcher-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Bean头部 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- 激活@Controller模式 -->
<mvc:annotation-driven />
<!-- 对包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 需要更改 -->
<context:component-scan base-package="com.gillian.controller" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
头不是这个吗?