web.xml
<!--
- Loads the root application context of this web app at startup, - by
default from "/WEB-INF/applicationContext.xml". - Note that you need
to fall back to Spring's ContextLoaderServlet for - J2EE servers that
do not follow the Servlet 2.4 initialization order. - - Use
WebApplicationContextUtils.getWebApplicationContext(servletContext) -
to access it anywhere in the web application, outside of the
framework. - - The root context is the parent of all servlet-specific
contexts. - This means that its beans are automatically available in
these child contexts, - both for getBean(name) calls and (external)
bean references.
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
- Servlet that dispatches request to registered handlers (Controller
implementations). - Has its own application context, by default
defined in "{servlet-name}-servlet.xml", - i.e.
"eventlog-servlet.xml". - - A web app can contain any number of such
servlets. - Note that this web app has a shared root application
context, serving as parent - of all DispatcherServlet contexts.
-->
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
abc-servlet.xml
<bean
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.Exception">uncaughtException</prop>
<prop key="org.springframework.dao.DataAccessException">dataAccessException</prop>
<prop key="org.springframework.transaction.TransactionException">dataAccessFailure</prop>
<!-- <prop key="com.rdps.eventlog.exception.EventLogException">eventLogException</prop>-->
</props>
</property>
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
Controller:
@Controller
@RequestMapping("/xxx.do")
@SessionAttributes({"aaa","bbb"})
public class xxxController {
@RequestMapping(method = RequestMethod.GET)
public String setupForm(Model model)throws Exception {
Event newEvent=generateDefaultEvent();
AddEventDisplayData addEventDisplayData = new AddEventDisplayData(newEvent);
setupFormCommon(model,addEventDisplayData);
return "addEvent";
}
@RequestMapping(method = RequestMethod.GET,params = "actionType=fromTask")
public String setupTaskForm(Model model, String taskId)throws Exception {
Task task = RMSService.getTaskById(Integer.parseInt(taskId));
return "addEvent";
}
@RequestMapping(method = RequestMethod.GET,params = "actionType=edit")
public String setupEditForm(Model model, String eventId, String fromReport, HttpServletRequest request)throws Exception {
List<EntityRow> typesList = RMSService.getTypesFromTeam(newEvent.getTeam().getId(),newEvent.getSource().getId());
model.addAttribute("typesList", typesList);
return "addEvent";
}
@RequestMapping(method = RequestMethod.POST)
public String processSubmit(HttpServletRequest request,Model model,AddEventDisplayData addEventDisplayData,BindingResult result, SessionStatus status) throws Exception {
validate(addEventDisplayData,result);
if (!result.hasErrors()) {
generateEvent(addEventDisplayData, request);
Event event = addEventDisplayData.getEvent();
if(event.getPreviousEventId()==null || event.getPreviousEventId().length()==0) {
RMSService.createEvent(event);
status.setComplete();
return "redirect:listEvent.do?message=msg.addEventLogSuccess";
}
else {
RMSService.editEvent(event);
String returnView= "redirect:listEvent.do?message=msg.modifyEventLogSuccess";
if (request.getSession().getAttribute("fromReport") != null) {
returnView="redirect:searchEvent.do?getResult=y&fromReport=y&message=msg.modifyEventLogSuccess";
}
status.setComplete();
return returnView;
}
}
else {
return "addEvent";
}
}
/**
* get sources for Add Event page, in order that the new event's source can be
* selected.
* @return List
*/
@ModelAttribute("sources")
public List<Source> getSources() {
return RMSService.getSources();
}
}
jsp
<form:form modelAttribute="addEventDisplayData" onsubmit="return checkData()">
<table class="func_table" id="main_table" width="900">
<tr>
<td class="table_title" colspan="2">
<c:choose>
<c:when test="${addEventDisplayData.edit}">
Modify Event
</c:when>
<c:otherwise>
Add New Event
</c:otherwise>
</c:choose>
</td>
</tr>
<tr>
<td colspan="2">
<table width="80%" cellspacing="0" cellpadding="2">
<tr>
<td align="center" width="10%">Source</td>
<td align="left" width="30%">
<form:select path="event.source.id" onchange="getEventTypes()" cssStyle="width: 150px;">
<form:options items="${sources}" itemValue="id" itemLabel="name"/>
</form:select>
</td>
<td align="center" width="10%">Team</td>
<td align="left" width="30%">
<form:select path="event.team.id" onchange="getEventTypes(); getEventUsers(this)" cssStyle="width: 150px;">
<form:options items="${teams}" itemValue="id" itemLabel="name" />
</form:select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td nowrap align="center">Team member</td>
<td id="teamMember">
<table border="0">
<tr>
<td>
<select multiple="true" id="allTeamUsers" style="width: 150px; height: 150px;">
<c:forEach var="member" items="${teamMembersList}">
<option value="${member.id}">${member.name}</option>
</c:forEach>
</select>
</td>
<td style="color: #333333;" width="80" align="center">
<input id="add" name="add" type="button" value=">" onclick="addUser()" class="button_small"><br><br>
<input id="remove" name="remove" type="button" value="<" onclick="removeUser()" class="button_small"><br><br>
<input id="addAll" name="addAll" type="button" value=">>" onclick="addAllUsers()" class="button_small"><br><br>
<input id="removeAll" name="removeAll" type="button" value="<<" onclick="removeAllUsers()" class="button_small">
</td>
<td>
<form:select path="members" multiple="true" id="selectedUsers" cssStyle="width: 150px; height: 150px;">
<c:forEach var="member" items="${selectedMembersList}">
<form:option value="${member.id}">${member.name}</form:option>
</c:forEach>
</form:select>
<form:errors path="members" cssClass="font_error" />
<label id="memberError" class="font_error" style="display:none"></label>
</td>
</tr>
</table>
</td>
分享到:
相关推荐
Spring MVC 实例
Spring MVC 实例 - Hello World,spring mvc 入门Spring MVC 实例 - Hello World,spring mvc 入门
学习Spring MVC,关于注解的Spring MVC,简单例子,关于控制器的Spring MVC,学习Spring,简单Spring MVC实例
Spring Mvc实例 主要实现利用spring注解,完成前后台交互,简单的视图控制和数据操作。
这是一个Spring MVC实例 使用MVC注解配置
运用extjs2和spring mvc的项目,非常具有学习价值,里面有一套非常好用的jdbc技术.
Spring mvc 实例下载可运行
Spring mvc 实例
基于注解的spring mvc,dao 层注解:@Repository("userDao"), entity层注解:@Entity,service层注解:@Service("userService"), action层注解:@Controller("userController") @RequestMapping("/user.do")
Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于...
Spring mvc、 Spring、 Spring jdbc 整合实例源码
首先, 我需要在你心里建立起 Spring MVC 的基本概念. 基于 Spring 的 Web 应用程序接收到 http://localhost:8080/hello.do(事实上请求路径是 /hello.do) 的请求后, Spring 将这个请求交给一个名为 helloController ...
这是一个自己编辑的实例使用与初学者。spring mvc 这个是一个标准的。还有一个简单的方法。需要给我留下邮箱
(附带详细文档讲解) 开发环境:Apache Tomcat + MyEclipse6 + spring2.5 实现功能:用户登录,校验用户名和密码,如果正确返回成功页面上显示登陆信息
将压缩文件解压后,将脚本在数据库执行后,启动eclipse,切换工作空间为解压的目录,就可以使用了
首先, 我需要在你心里建立起 Spring MVC 的基本概念. 基于 Spring 的 Web 应用程序接收到 http://localhost:8080/hello.do(事实上请求路径是 /hello.do) 的请求后, Spring 将这个请求交给一个名为 helloController ...
spring mvc简单实例,来自官网
完整的Spring+MVC+AngularJS例子 maven项目。