标题:[求助]Spring的AbstractCommandController的问题
取消只看楼主
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
 问题点数:0 回复次数:1 
[求助]Spring的AbstractCommandController的问题

问下大家怎么用这个类啊?我编写了一个例子,但不太理解:
UserController.java:

package src;

import org.springframework.web.servlet.mvc.AbstractCommandController;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;

public class UserController extends AbstractCommandController{
public UserController(){
setCommandClass(User.class);
}

protected ModelAndView handle(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException exception) throws Exception{
User user=(User) command;
name=user.getName();
String nameAndPassword=name+" "+user.getPassword();
return new ModelAndView("User","userinfo",nameAndPassword);
}

private String name;
private String password;
public void setName(String name){
this.name=name;
}
public void setPassword(String password){
this.password=password;
} //红色部分是必需的吗?还是可以不要?
}
User.java:
package src;

public class User {
private String name;
private String password;
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public void setPassword(String password){
this.password=password;
}
public String getPassword(){
return password;
}
}
配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<bean id="user" class="src.UserController">

</bean>

<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/aaa.htm">aaa</prop>
<prop key="/home.htm">home</prop>
<prop key="/course.htm">courseService</prop>
<prop key="/user.htm">user</prop>
</props>
</property>
</bean>



<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>
最后要显示的View(User.jsp):
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>User Information</title>
</head>
<body>
<h2>${userinfo }</h2>
</body>
</html>
问题就是,当我在地址栏里面输入user.htm的时候,显示出来的是2个null。怎么使用AbstractCommandController来传递参数啊?用这个类有什么好处?还有就是红色字体的部分的问题。谢谢大家耐心点看啊!

搜索更多相关主题的帖子: Spring import web servlet org 
2007-09-06 15:58
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
得分:0 
呃,还有个问题,为什么我发的内容都被框起来了?怎么才能不被框起来啊?不然很难看清楚的

I'm here, as always...
2007-09-06 16:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-168144-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.186609 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved