控制器:
@Controller
@Scope("request")
public class PersonController {
@Secured("ROLE_USER")
@RequestMapping(value = "/loadsection/{id}")
public String loadNotePage(@PathVariable("id") Integer id, HttpSession session) {
// here i am setting the canvasid, which I would like to access in other methods
session.setAttribute("canvasid",id);
if (this.personService.returnCurrentOperationalMode()) {
session.setAttribute("canvasid",id);
return "redirect:/section/listing";
} else {
GroupCanvas mcanvas = this.groupCanvasService.getCanvasById(id);
this.personService.setCurrentCanvas(mcanvas.getMcanvasid());
return "redirect:/section/listing";
}
}
@Secured("ROLE_USER")
@RequestMapping(value = "/addbatchsections", method = RequestMethod.POST)
public @ResponseBody String addBatchSections(HttpSession session, @RequestBody Section[] sections) {
int canvasid = (Integer) session.getAttribute("canvasid");
try {
List<Section> sectionList = new ArrayList<>();
for (Section section : sections) {
sectionList.add(section);
}
this.sectionService.addBatchSections(sectionList,canvasid);
return "success";
} catch (Exception e) {
return "failure";
}
}
Servlet的context.xml中
<mvc:annotation-driven/>
<mvc:default-servlet-handler/>
<resources mapping="/resources/" location="/resources/" />
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<beans:property name="driverClassName" value="org.postgresql.Driver" />
<beans:property name="url"
value="jdbc:postgresql://localhost:5432/Person2"/>
<beans:property name="username" value="postgres" />
<beans:property name="password" value="asayhk2787" />
<beans:property name="removeAbandoned" value="true"/>
<beans:property name="removeAbandonedTimeout" value="20"/>
<beans:property name="defaultAutoCommit" value="false"/>
</beans:bean>
<!-- Hibernate 4 SessionFactory Bean definition -->
<beans:bean id="hibernate4AnnotatedSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="annotatedClasses">
<beans:list>
<beans:value>com.journaldev.spring.model.Person</beans:value>
<beans:value>com.journaldev.spring.model.Notes</beans:value>
<beans:value>com.journaldev.spring.model.Canvas</beans:value>
<beans:value>com.journaldev.spring.model.Section</beans:value>
<beans:value>com.journaldev.spring.model.Attachment</beans:value>
<beans:value>com.journaldev.spring.model.GroupAccount</beans:value>
<beans:value>com.journaldev.spring.model.GroupMembers</beans:value>
<beans:value>com.journaldev.spring.model.GroupCanvas</beans:value>
<beans:value>com.journaldev.spring.model.GroupSection</beans:value>
<beans:value>com.journaldev.spring.model.GroupNotes</beans:value>
<beans:value>com.journaldev.spring.model.GroupAttachments</beans:value>
<beans:value>com.journaldev.spring.model.Token</beans:value>
<beans:value>com.journaldev.spring.model.WaitingMembers</beans:value>
<beans:value>com.journaldev.spring.model.NoteHistory</beans:value>
<beans:value>com.journaldev.spring.model.GroupNoteHistory</beans:value>
<beans:value>com.journaldev.spring.model.Feedback</beans:value>
</beans:list>
</beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL82Dialect
</beans:prop>
<beans:prop key="hibernate.show_sql">false</beans:prop>
<beans:prop key="connection.pool_size">200</beans:prop>
<beans:prop key="c3p0.max_size">200</beans:prop>
<beans:prop key="c3p0.timeout">1000</beans:prop>
<beans:prop key="hibernate.jdbc.batch_size">100</beans:prop>
<beans:prop key="hibernate.order_updates">true</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<beans:bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory"/>
</beans:bean>
我希望我的问题很明确,如果有任何疑问,请随时问我。非常感谢。 : - )
答案 0 :(得分:1)
查看Spring Session及其相关示例。
答案 1 :(得分:0)
新标签页或新窗口上的Chrome浏览器共享用户会话,因为使用相同的会话Cookie。
检查this或更改会话方法。