导航:首页 > 编程语言 > javarender

javarender

发布时间:2022-09-05 04:00:18

A. 求java画图版,能画正多边形的代码!

public class MiniDraw implements ActionListener, MouseListener{ // Fields private JFrame frame = new JFrame("MiniDraw");
private DrawingCanvas canvas = new DrawingCanvas(); private JButton colorButton; // the button for colour, so we can change its background to the current color.
private JTextField textField; // the field for entering text to put on the canvas // fields for recording the information needed to perform the next action
private enum Action {Line,Rect, Oval, Triangle, Text, Dot, Move, Delete, Push, Pull}; private int pressedX; //where the mouse was pressed
private int pressedY; //where the mouse was pressed
private Action currentAction = Action.Line;
private Color currentColor = Color.black; private List<Shape> shapes = new ArrayList <Shape>();

/** Constructor sets up the GUI. */
public MiniDraw(){
frame.setSize(800,600); //The graphics area
canvas.addMouseListener(this);
frame.getContentPane().add(canvas, BorderLayout.CENTER); //The buttons
JPanel topPanel = new JPanel( );
frame.getContentPane().add(topPanel, BorderLayout.NORTH);
JPanel botPanel = new JPanel( );
frame.getContentPane().add(botPanel, BorderLayout.SOUTH);
addButton(topPanel, "New");
addButton(topPanel, "Open");
addButton(topPanel, "Save");
addButton(topPanel, "Delete");
addButton(topPanel, "Move");
colorButton = addButton(topPanel, "Color"); // remember the button so we can change its colour
addButton(topPanel, "Push");
addButton(topPanel, "Pull");
addButton(topPanel, "Reverse");
addButton(topPanel, "Quit"); botPanel.add(new JLabel("Shapes: "));
addButton(botPanel, "Line");
addButton(botPanel, "Rect");
addButton(botPanel, "Oval");
addButton(botPanel, "Triangle");
addButton(botPanel, "Dot");
addButton(botPanel, "Text");
textField = new JTextField("Enter text", 12);
botPanel.add(new JLabel(" : "));
botPanel.add(textField); frame.setVisible(true);
} /** Utility method to make new button and add it to the panel
Returns the button, in case we need it. */
private JButton addButton(JPanel panel, String name){
JButton button = new JButton(name);
button.addActionListener(this);
panel.add(button);
return button;
} /** Respond to button presses */ public void actionPerformed(ActionEvent e){
String button = e.getActionCommand();
//System.out.printf("Button: %s\n", button); //for debugging
if (button.equals("New") )
newDrawing();
else if (button.equals("Open") )
openDrawing();
else if (button.equals("Save") )
saveDrawing();
else if (button.equals("Color") )
selectColor();
else if (button.equals("Reverse") )
reverseDrawing();
else if (button.equals("Quit") )
frame.dispose();
else{ //
currentAction = Action.valueOf(button); // converts the String to an Action.
}
} /** Sets the current color.
* Also changes the color of the Color button and sets the background color of the canvas */
private void selectColor(){
Color newColor = JColorChooser.showDialog(frame,"Choose Color for new shapes", currentColor);
if (newColor!=null){
currentColor=newColor;
colorButton.setBackground(currentColor);
}
} // Respond to mouse events
/** When mouse is pressed, remember the position in order to construct the Shape when
* the mouse is released. */
public void mousePressed(MouseEvent e) {
int x = e.getX(); int y = e.getY();
//System.out.printf("Pressed at (%d, %d)\n", x, y); //for debugging
pressedX = x;
pressedY = y;
} /** When the Mouse is released, depending on the currentAction,
* either construct the shape that was being drawn, or perform the
* action (delete or move) on the shape under the point where the mouse was pressed.*/

public void mouseReleased(MouseEvent e) {
int x = e.getX(); int y = e.getY();
//System.out.printf("Released at (%d, %d)\n", x, y); //for debugging
if (currentAction==Action.Move)
moveShape(pressedX, pressedY, x, y);
else if (currentAction==Action.Delete)
deleteShape(x, y);
else if (currentAction==Action.Push)
pushShapeBackward(x, y);
else if (currentAction==Action.Pull)
pullShapeForward(x, y);
else
addShape(pressedX, pressedY, x, y);
} public void mouseClicked(MouseEvent e) {} //needed to satisfy interface
public void mouseEntered(MouseEvent e) {} //needed to satisfy interface
public void mouseExited(MouseEvent e) {} //needed to satisfy interface
// Helper methods for implementing the button and mouse actions

/** Start a new drawing. */
public void newDrawing(){
shapes = new ArrayList<Shape>();
canvas.clear();
}
/** Open a file, and read all the shape descriptions into the current drawing. */
public void openDrawing(){
String fname = FileChooser.open();
if (fname==null) return;
try {
Scanner file = new Scanner(new File(fname));
//System.out.printf("Opening file %s\n", fname);
shapes = new ArrayList<Shape>();
while (file.hasNext()){
String shapetype = file.next().toLowerCase();
if (shapetype.equals("oval"))
shapes.add(new Oval(file));
else if (shapetype.equals("rectangle"))
shapes.add(new Rectangle(file));
if (shapetype.equals("line"))
shapes.add(new Line(file));
if (shapetype.equals("textshape"))
shapes.add(new TextShape(file));
else if (shapetype.equals("triangle"))
shapes.add(new Triangle(file));
else if (shapetype.equals("dot"))
shapes.add(new Dot(file));
}
render();
}
catch(IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
} /** Save the current drawing to a file. */
public void saveDrawing(){
String fname =FileChooser.save();
if ( fname == null )
return;
try{
PrintStream f = new PrintStream( new File( fname ));
for ( Shape shape : shapes )
f.println( shape.toString());
f.close ();
}
catch(IOException ex){
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
/** Returns the shape under the position (x y), or null if no such shape */
public Shape findShape(int x, int y){
for (int i = shapes.size()-1; i>=0; i--){ // must go backwards, so can't use foreach
Shape shape = shapes.get(i);
if (shape.pointOnShape(x, y))
return shape;
}
return null; // no shape found at position
}
/** Moves the shape that was under the mousePressed position (pressedX, pressedY)
to where the mouse was released.
Ie, move it by (newX-pressedX) and (newY-pressedY)
*/
public void moveShape(int fromX, int fromY, int toX, int toY){
//System.out.printf("Moving shape under (%d, %d) to (%d, %d)\n", pressedX, pressedY, newX, newY); //for debugging
Shape shape = findShape(fromX, fromY);
if (shape!= null)
shape.moveBy((toX-fromX), (toY-fromY));
render();
} /** Deletes the shape that was under the mouseReleased position (x, y)
*/
public void deleteShape(int x, int y){ for ( Shape shape : shapes) {
if ( shape.pointOnShape(x, y ))
shapes.remove ( shape );
}
render();
}
/** Pull the shape under the mouse one position closer to the "front"
of the drawing */
public void pullShapeForward(int x, int y){
// System.out.printf("Pulling shape under (%d, %d) forward\n", x, y); //for debugging
// YOUR CODE HERE
Shape shape = findShape( x, y );
if (shape!=null ) {
int index = shapes.indexOf(shape);
if ( index< shapes.size()-1){
shapes.remove(index);
shapes.add( index+1,shape);
}
render();

}
}
/** Push the shape under the mouse one position further from the "front"
of the drawing */
public void pushShapeBackward(int x, int y){
//System.out.printf("Pushing shape under (%d, %d) backward\n", x, y); //for debugging
// YOUR CODE HERE
Shape shape = findShape(x, y );
if ( shape!=null ){
int index = shapes.indexOf(shape);
if( index > 0 )
shapes.remove( index);
shapes.add( index-1, shape);
}
render();

}

/** Reverse the order of the shapes in the drawing */
public void reverseDrawing(){ List<Shape>temp = new ArrayList<Shape>();
while ( shapes.size() > 0 ) {
temp.add ( shapes.remove(shapes.size()-1));
}
shapes= temp;
render();

}
/** Construct a new Shape object of the appropriate kind (depending on currentAction)
Uses the appropriate constructor of the Line, Rectangle, Oval, TextShape, or Triangle classes.
adds the shape it to the collection of shapes in the drawing, and
renders the shape on the canvas */
public void addShape(int x1, int y1, int x2, int y2){
//System.out.printf("Drawing shape %s, at (%d, %d)-(%d, %d)\n", currentAction, pressedX, pressedY, x, y); //for debugging
Shape shape = null;
if (currentAction==Action.Line)
shapes.add(new Line(x1, y1, x2, y2, currentColor));
if (currentAction==Action.Triangle)
shapes.add(new Triangle(x1, y1, x2, y2, currentColor));
if (currentAction==Action.Dot)
shapes.add(new Dot(x2, y2, currentColor));
else if (currentAction==Action.Text)
shapes.add(new TextShape(x2, y2, textField.getText(), currentColor));
else{
int left= Math.min(x1, x2);
int top= Math.min(y1, y2);
int width= Math.abs(x1 - x2);
int height= Math.abs(y1 - y2);
if (currentAction==Action.Rect)
shapes.add(new Rectangle(left, top, width, height, currentColor));
else if (currentAction==Action.Oval)
shapes.add(new Oval(left, top, width, height, currentColor));
}
render();
} public void render(){
canvas.clear(false);
for (Shape shape : shapes){
shape.render(canvas);
}
canvas.display();
} public static void main(String args[]){
new MiniDraw();
}}

B. 求后台运行java方法向前台推数据例子

play框架:

/**后台**/
Map<String,Object> queryStudent = Stock.queryStudent();//返回一个queryStudent的map
render(queryStudent );//render这个queryStudent 。

<!-- 页面 -->
学生一共有${queryStudent ?.sumId}人<!-- 页面上引用就好了 -->

C. 什么是java过滤器! 它的功能和作用是什么啊

Filter 技术是servlet 2.3 新增加的功能.servlet2.3是sun公司与2000年10月发布的,它的开发者包括许多个人和公司团体,充分体现了sun公司所倡导的代码开放性原则.由于众多的参与者的共同努力,servlet2.3比以往功能都强大了许多,而且性能也有了大幅提高.
它新增加的功能包括:
1. 应用程序生命周期事件控制;
2. 新的国际化;
3. 澄清了类的装载规则;
4. 新的错误及安全属性;
5. 不赞成使用HttpUtils 类;
6. 各种有用的方法;
7. 阐明并扩展了几个servlet DTD;
8. filter功能.
其中最重要的就是filter功能.它使用户可以改变一个request和修改一个 response. Filter 不是一个servlet,它不能产生一个response,它能够在一个request到达servlet之前预处理request,也可以在离开 servlet时处理response.换种说法,filter其实是一个”servlet chaining”(servlet 链).一个filter 包括:
1. 在servlet被调用之前截获;
2. 在servlet被调用之前检查servlet request;
3. 根据需要修改request头和request数据;
4. 根据需要修改response头和response数据;
5. 在servlet被调用之后截获.
你能够配置一个filter 到一个或多个servlet;单个servlet或servlet组能够被多个filter 使用.几个实用的filter 包括:用户辨认filter,日志filter,审核filter,加密filter,符号filter,能改变xml内容的XSLT filter等.
一个filter必须实现javax.servlet.Filter接口并定义三个方法:
1.void setFilterConfig(FilterConfig config) //设置filter 的配置对象;
2. FilterConfig getFilterConfig() //返回filter的配置对象;
3. void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) //执行filter 的工作.
服务器每次只调用setFilterConfig方法一次准备filter 的处理;调用doFilter方法多次以处理不同的请求.FilterConfig接口有方法可以找到filter名字及初始化参数信息.服务器可以设置 FilterConfig为空来指明filter已经终结.
每一个filter从doFilter()方法中得到当前的request及 response.在这个方法里,可以进行任何的针对request及response的操作.(包括收集数据,包装数据等).filter调用 chain.doFilter()方法把控制权交给下一个filter.一个filter在doFilter()方法中结束.如果一个filter想停止 request处理而获得对response的完全的控制,那它可以不调用下一个filter.
一个filter可以包装request 或response以改变几个方法和提供用户定制的属性.Api2.3提供了HttpServletRequestWrapper 和HttpServletResponseWrapper来实现.它们能分派最初的request和response.如果要改变一个方法的特性,必须继承wapper和重写方法.下面是一段简单的日志filter用来记录所有request的持续时间.
public class LogFilter implements Filter {
FilterConfig config;
public void setFilterConfig(FilterConfig config) {
this.config = config;
}
public FilterConfig getFilterConfig() {
return config;
}
public void doFilter(ServletRequest req,
ServletResponse res,
FilterChain chain) {
ServletContext context = getFilterConfig().getServletContext();
long bef = System.currentTimeMillis();
chain.doFilter(req, res); // no chain parameter needed here
long aft = System.currentTimeMillis();
context.log("Request to " + req.getRequestURI()
+ ": " + (aft-bef));
}
}
当server调用setFilterConfig(),filter保存config信息. 在doFilter()方法中通过config信息得到servletContext.如果要运行这个filter,必须去配置到web.xml中.以 tomcat4.01为例:
<filter>
<filter-name>
log //filter 名字
</filter-name>
<filter-class>
LogFilter //filter class(上例的servlet)
</filter-class>
</filter>
<filter-mapping>
<filter-name>log</filter-name>
<servletname>servletname</servlet-name>
</filter-mapping>
<servlet>
<servlet-name>servletname</servletname>
<servletclass>servletclass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servletname</servlet-name>
<url-pattern>*</url-pattern>
</servlet-mapping>
把这个web.xml放到web-inf中(详请参考tomcat帮助文档).
当每次请求一个request时(如index.jsp),先到LogFilter中去并调用doFilter()方法,然后才到各自的servlet中去.如果是一个简单的servlet(只是一个页面,无任何输出语句),那么可能的输出是:
Request to /index.jsp: 10
Filter是一个COM组件,由一个或多个Pin组成。Pin也是一个COM组件。 Filter文件的扩展名为.ax,但也可以是.dll。Filter根据其包含Input pin或Output pin的情况(或在Filter Graph的位置),大致可分为三类:Source Filter(仅有Output pin)、Transform Filter(同时具有Input pin和Output pin)和Renderer Filter(仅有Input pin)。
一般情况下,创建Filter使用一个普通的Win32 DLL项目。而且,一般Filter项目不使用MFC。这时,应用程序通过CoCreateInstance函数Filter实例;Filter与应用程序在二进制级别的协作。另外一种方法,也可以在MFC的应用程序项目中创建Filter。这种情况下,Filter不需注册为COM组件,Filter与应用程序之间的协作是源代码级别的;创建Filter实例,不再使用CoCreateInstance函数,而是直接new出一个Filter对象,如下:
m_pFilterObject = new CFilterClass();
// make the initial refcount 1 to match COM creation
m_pFilterObject ->AddRef();
因为Filter的基类实现了对象的引用计数,所以即使在第二种情况下,对创建后的Filter对象的操作也完全可以遵循COM标准。
Filter是一个独立功能模块,最好不要将Filter依赖于其他第三方的DLL。因为 Filter具有COM的位置透明性特点,Filter文件可以放在硬盘的任何位置,只要位置移动后重新注册。但此时,如果Filter依赖其他DLL,则Filter对该DLL的定位就会出现问题。
Filter不能脱离Filter Graph单独使用。所以,如果你想绕过Filter Graph直接使用Filter实现的模块功能,请将你的Filter移植成DMO(DirectX Media Object)。对于DirectShow应用程序开发者来说,还有一点,请不要忘记使用OleInitialize进行初始化。
2. Filter的注册
Filter是COM组件,所以在使用前一定要注册。Filter的注册程序为 regsvr32.exe。如果带上命令行参数/u,表示注销;如果带上是/s,表示不弹出任何注册/注销成功与否的提示对话框。如果你想在Build Filter项目的时候进行自动注册,请在VC的Project settings的Custom Build页如下设置:
Description: Register filter
Commands: regsvr32 /s /c $(TargetPath)
echo regsvr32 exe.time > $(TargetDir)\$(TargetName).trg
Outputs: $(TargetDir)\$(TargetName).trg
Filter的注册信息包括两部分:基本的COM信息和Filter信息。注册信息都存放在注册表中。前者的位置为:HKEY_CLASSES_ROOT\CLSID\Filter Clsid\,后者的位置为:HKEY_CLASSES_ROOT\CLSID\Category\Instance\ Filter Clsid\。COM信息标示了Filter是一个标准的可以通过CoCreateInstance函数创建的COM组件,Filter信息标示了我们通过Graphedit看到的描述这个Filter的信息。如果你不想让Graphedit看到(或者让Filter枚举器找到)你写的Filter,你完全可以不注册Filter信息。而且不用担心,你这么做也完全不会影响Filter的功能。
屏蔽注册Filter信息的方法也很简单。因为CBaseFilter实现了IAMovieSetup接口的两个函数:Register和Unregister。我们只需重载这两个函数,直接return S_OK就行了。
Filter的Merit值。这个值是微软的“智能连接”函数使用的。在Graphedit中,当我们加入一个Source Filter后,在它的pin上执行“Render”,会自动连上一些Filter。Merit的值参考如下:
MERIT_PREFERRED = 0x800000,
MERIT_NORMAL = 0x600000,
MERIT_UNLIKELY = 0x400000,
MERIT_DO_NOT_USE = 0x200000,
MERIT_SW_COMPRESSOR = 0x100000,
MERIT_HW_COMPRESSOR = 0x100050
Merit值只有大于MERIT_DO_NOT_USE的时候才有可能被“智能连接”使用;Merit的值越大,这个Filter的机会就越大。
3. Filter之间Pin的连接过程
Filter只有加入到Filter Graph中并且和其它Filter连接成完整的链路后,才会发挥作用。Filter之间的连接(也就是Pin之间的连接),实际上是连接双方的一个 Media type的协商过程。连接的方向总是从Output pin指向Input pin。连接的大致过程为:如果调用连接函数时已经指定了完整的Media type,则用这个Media type进行连接,成功与否都结束连接过程;如果没有指定或不完全指定了Media type,则进入下面的枚举过程。枚举欲连接的Input pin上所有的Media type,逐一用这些Media type与Output pin进行连接(如果连接函数提供了不完全Media type,则要先将每个枚举出来的Media type与它进行匹配检查),如果Output pin也接受这种Media type,则Pin之间的连接宣告成功;如果所有Input pin上枚举的Media type,Output pin都不支持,则枚举Output pin上的所有Media type,并逐一用这些Media type与Input pin进行连接。如果Input pin接受其中的一种Media type,则Pin之间的连接到此也宣告成功;如果Output pin上的所有Media type,Input pin都不支持,则这两个Pin之间的连接过程宣告失败。
每个Pin都可以实现GetMediaType函数来提供该Pin上支持的所有 Preferred Media type(但一般只在Output pin上实现,Input pin主要实现CheckMediaType看是否支持当前提供的Media type就行了)。连接过程中,Pin上枚举得到的所有Media type就是这里提供的。
在CBasePin类中有一个protected的成员变量 m_bTryMyTypesFirst,默认值为false。在我们定制Filter的Output pin中改变这个变量的值为true,可以定制我们自己的连接过程(先枚举Output pin上的Media type)。
当Pin之间的连接成功后,各自的pin上都会调用CompleteConnect函数。我们可以在这里取得一些连接上的Media type的信息,以及进行一些计算等。在Output pin的CompleteConnect实现中,还有一个重要的任务,就是协商Filter Graph运行起来后Sample传输使用的内存配置情况。这同样是一个交互过程:首先要询问一下Input pin上的配置要求,如果Input pin提供内存管理器(Allocator),则优先使用Input pin上的内存管理器;否则,使用Output pin自己生成的内存管理器。我们一般都要实现DecideBufferSize来决定存放Sample的内存大小。注意:这个过程协商完成之后,实际的内存并没有分配,而要等到Output pin上的Active函数调用。
4. Filter Media type概述
Media type一般可以有两种表示:AM_MEDIA_TYPE和CMediaType。前者是一个Struct,后者是从这个Struct继承过来的类。
每个Media type有三部分组成:Major type、Subtype和Format type。这三个部分都使用GUID来唯一标示。Major type主要定性描述一种Media type,比如指定这是一个Video,或Audio或Stream等;Subtype进一步细化Media type,如果Video的话可以进一步指定是UYVY或YUY2或RGB24或RGB32等;Format type用一个Struct更进一步细化Media type。
如果Media type的三个部分都是指定了某个具体的GUID值,则称这个Media type是完全指定的;如果Media type的三个部分中有任何一个值是GUID_NULL,则称这个Media type 是不完全指定的。GUID_NULL具有通配符的作用。
常用的Major type:
MEDIATYPE_Video;
MEDIATYPE_Audio;
MEDIATYPE_AnalogVideo; // Analog capture
MEDIATYPE_AnalogAudio;
MEDIATYPE_Text;
MEDIATYPE_Midi;
MEDIATYPE_Stream;
MEDIATYPE_Interleaved; // DV camcorder
MEDIATYPE_MPEG1SystemStream;
MEDIATYPE_MPEG2_PACK;
MEDIATYPE_MPEG2_PES;
MEDIATYPE_DVD_ENCRYPTED_PACK;
MEDIATYPE_DVD_NAVIGATION;
常用的Subtype:
MEDIASUBTYPE_YUY2;
MEDIASUBTYPE_YVYU;
MEDIASUBTYPE_YUYV;
MEDIASUBTYPE_UYVY;
MEDIASUBTYPE_YVU9;
MEDIASUBTYPE_Y411;
MEDIASUBTYPE_RGB4;
MEDIASUBTYPE_RGB8;
MEDIASUBTYPE_RGB565;
MEDIASUBTYPE_RGB555;
MEDIASUBTYPE_RGB24;
MEDIASUBTYPE_RGB32;
MEDIASUBTYPE_ARGB32; // Contains alpha value
MEDIASUBTYPE_Overlay;
MEDIASUBTYPE_MPEG1Packet;
MEDIASUBTYPE_MPEG1Payload; // Video payload
MEDIASUBTYPE_MPEG1AudioPayload; // Audio payload
MEDIASUBTYPE_MPEG1System; // A/V payload
MEDIASUBTYPE_MPEG1VideoCD;
MEDIASUBTYPE_MPEG1Video;
MEDIASUBTYPE_MPEG1Audio;
MEDIASUBTYPE_Avi;
MEDIASUBTYPE_Asf;
MEDIASUBTYPE_QTMovie;
MEDIASUBTYPE_PCM;
MEDIASUBTYPE_WAVE;
MEDIASUBTYPE_dvsd; // DV
MEDIASUBTYPE_dvhd;
MEDIASUBTYPE_dvsl;
MEDIASUBTYPE_MPEG2_VIDEO;
MEDIASUBTYPE_MPEG2_PROGRAM;
MEDIASUBTYPE_MPEG2_TRANSPORT;
MEDIASUBTYPE_MPEG2_AUDIO;
MEDIASUBTYPE_DOLBY_AC3;
MEDIASUBTYPE_DVD_SUBPICTURE;
MEDIASUBTYPE_DVD_LPCM_AUDIO;
MEDIASUBTYPE_DVD_NAVIGATION_PCI;
MEDIASUBTYPE_DVD_NAVIGATION_DSI;
MEDIASUBTYPE_DVD_NAVIGATION_PROVIDER;
常用的Format type:
FORMAT_None
FORMAT_DvInfo DVINFO
FORMAT_MPEGVideo MPEG1VIDEOINFO
FORMAT_MPEG2Video MPEG2VIDEOINFO
FORMAT_VideoInfo VIDEOINFOHEADER
FORMAT_VideoInfo2 VIDEOINFOHEADER2
FORMAT_WaveFormatEx WAVEFORMATEX
5. Filter之间的数据传送
Filter之间的数据是通过Sample来传送的。Sample是一个COM组件,拥有自己的一段数据缓冲。Sample由Allocator统一管理。如下图所示:
Filter之间数据传送的方式有两种:Push模式和Pull模式。

D. java jtable表头名相同时,cellrender渲染器无法设置表头名相同的列

楼主,具体的render是如何写的。。。。。。

你上面是getColumnName那有三个列名相同喔,这样应该可以的了

table.getColumnModel().getColumn(0).setCellRenderer(render);

E. 求一段JAVA代码要求如下 获取输入的字段和数据库中的比较如果没有就把该字段存入数据库 数据库 STUDENT

这个是重复的验证,你可以在jsp页面通过Ajax,将输入的值传到后台Action,在Action里把该值放入查询语句到数据库进行查询,进行重复判断。

js代码如下:
var f = document.forms[0];
$("#role_name").blur(function(){
if(null == f.role_name.value){
return ;
}
$.ajax({
type: "POST",
url: "RoleInfo.do",
data: "method=validateRolename&id=${af.map.id}&role_name=" + f.role_name.value,
dataType: "json",
error: function(request, settings) {},
success: function(oper) {
if(oper.result){
$("#role_name").val("");
alert("系统已存在此角色");
f.role_name.focus();
}else {
return;
}
}
});
Action代码:
public ActionForward validateRolename(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {

DynaBean dynaBean = (DynaBean) form;
StringBuffer oper = new StringBuffer("{result:");
String role_name = (String) dynaBean.get("role_name");
//String id = (String) dynaBean.get("id");

if (!StringUtils.isBlank(role_name)) {
RoleInfo ri = new RoleInfo();
ri.setRole_name(role_name);
//if(null != id){
ri.getMap().put("id_not_in",(String) dynaBean.get("id"));
//}
ri = super.getFacade().getRoleInfoService().getRoleInfo(ri);
if (null == ri) {
oper.append(false);
} else {
oper.append(true);
}
} else {
oper.append("error");
}

oper.append("}");
super.render(response, oper.toString(), "text/x-json;charset=UTF-8");
return null;

}

F. Java中ModelAndView是做什么的

ModelAndView以org.springframework.ui.ModelMap的形式来保持模型数据,通过构造方法传入的或者通过实例方法添加的模型数据都将添加到这个ModelMap中。至于ModelMap中保持的模型数据将会在视图渲染阶段,由具体的View实现类来获取并使用。

我们需要为添加到ModelAndView的一组或者多组模型数据提供相应的键(Key),以便具体的View实现类可以根据这些键获取具体的模型数据,然后公开给视图模板。通常,模型中的数据对应的键需要与视图模板中的标志符相对应,如图所示:

基于JSP/JSTL模板的视图实现,通常是将模型数据通过HttpServletRequest的属性(Attribute)的形式公开给具体的模板。而像基于Velocity之类的通用模板引擎的视图实现,则会将ModelAndView中的模型数据复制到它们自己的数据获取上下文中,比如Velocity的Context。

但不管什么视图类型,对应的视图模板都将可以通过添加到ModelAndView的模型数据的键来获取模型数据,并合并到最终的视图输出结果中。

拓展资料:

ModelAndView 的构造方法有7个。但是它们都是相通的。这里使用无参构造函数来举例说明如何构造ModelAndView 实例。

ModelAndView 类别就如其名称所示,是代表了MVC Web程序中Model与View的对象,不过它只是方便您一次返回这两个对象的holder,Model与View两者仍是分离的概念。

最简单的ModelAndView是持有View的名称返回,之后View名称被view resolver,也就是实作org.springframework.web.servlet.View接口的实例解析,例如 InternalResourceView或JstlView等等。

ModelAndView(String viewName) 如果您要返回Model对象,则可以使用Map来收集这些Model对象,然后设定给ModelAndView,使用下面这个版本的 ModelAndView: ModelAndView(String viewName, Map model) Map对象中设定好key与value值。

之后可以在视图中取出,如果您只是要返回一个Model对象,则可以使用下面这个 ModelAndView版本: ModelAndView(String viewName, String modelName, Object modelObject) 借由modelName,您可以在视图中取出Model并显示。

web.servlet.View的实例,View接口如下: public interface View { public void render(Map model, HttpServletResquest resquest, HttpServletResponse response) throws ServletException, IOException; }

View的实作之前用过 org.springframework.web.servlet.view.InternalResourceView,另外也还有JstlView、 TilesView、VelocityView等等的实作,分别进行不同的表现展处理 。

ModelAndView() 这个构造方法构造出来的ModelAndView 不能直接使用,应为它没有指定view,也没有绑定对应的model对象。当然,model对象不是必须的,但是view确实必须的。 用这个构造方法构造的实例主要用来在以后往其中加view设置和model对象。

给ModelAndView 实例设置view的方法有两 个:setViewName(String viewName) 和 setView(View view)。前者是使用view name,后者是使用预先构造好的View对象。

其中前者比较常用。事实上View是一个接口,而不是一个可以构造的具体类,我们只能通过其他途径来获取 View的实例。对于view name,它既可以是jsp的名字,也可以是tiles定义的名字,取决于使用的ViewNameResolver如何理解这个view name。

如何获取View的实例以后再研究。 而对应如何给ModelAndView 实例设置model则比较复杂。有三个方法可以使用: addObject(Object modelObject) addObject(String modelName, Object modelObject) addAllObjects(Map modelMap) ModelAndView 可以接收Object类型的对象,ModelAndView 将它视为其众多model中的一个。

当使用Object类型的对象的时候,必须指定一个名字。ModelAndView 也可以接收没有明显名字的对象,原因在于ModelAndView 将调用spring自己定义的Conventions 类的.getVariableName()方法来为这个model生成一个名字。

阅读全文

与javarender相关的资料

热点内容
unix网络编程卷4 浏览:806
找靓机app下单什么时候发货 浏览:411
android一个应用两个进程 浏览:801
linux硬盘复制 浏览:806
php图片服务器搭建 浏览:799
下载压缩文件怎么打开 浏览:192
新建文件夹叫什么名字 浏览:565
windows20的开机命令 浏览:332
微信一般在电脑的那个文件夹 浏览:509
go在win7下编译特别慢 浏览:256
光遇ios耳机安卓为什么没有 浏览:904
小米手机桌面文件夹经常自动散开 浏览:607
小米电话手表用什么app进行设置 浏览:265
虚拟打印机pdf下载 浏览:671
jdk编译运行方法 浏览:459
android执行shell命令 浏览:349
程序员头像女 浏览:57
有什么可以变头发颜色的app 浏览:935
玩具解压屋游戏下载 浏览:849
我的世界拔刀剑服务器地址id 浏览:891