说明下@PathVariable和@RequestParam的区别

@RequestParam我明白将参数作为输入参数传入那么@RequestParam的作用是什么呢?springmvc中有哪些常用需要掌握的注解呢!... @RequestParam 我明白 将参数作为输入参数传入
那么@RequestParam的作用是什么呢?
spring mvc 中有哪些常用需要掌握的 注解呢!
展开
 我来答
皂的鸡4
2016-06-21 · TA获得超过817个赞
知道答主
回答量:587
采纳率:0%
帮助的人:129万
展开全部
//UploadServlet的JAVA代码,测试通过的,你看看
//如果还是不行的话,换成TOMCAT6.0试试
package com.test.servlet;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

public class Upload extends HttpServlet {

/**
* Constructor of the object.
*/
public Upload() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
Iterator items;
try {
items = upload.parseRequest(request).iterator();
while(items.hasNext()){
FileItem item = (FileItem) items.next();
if(!item.isFormField()){

String name = item.getName();
System.out.println(name);
String filename = name.substring(name.lastIndexOf("\\")+1);
System.out.println(filename);
String realpath = request.getRealPath("/upload");
String path = realpath+File.separatorChar+filename;
System.out.println(realpath);
System.out.println(path);
File file = new File(path);
item.write(file);

response.setContentType("text/html");
response.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
out.print("<font size='2'>上传的文件为:"+name+"<br>");
out.print("保存的地址为:"+path+"</font>");

}

}
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}
亚果会
2024-04-11 广告
Goma Greens是一家专注于提供高品质有机蔬果的企业。我们致力于为消费者带来新鲜、健康、无污染的食材,以满足现代人对健康生活的追求。我们的产品均来自精心挑选的有机农场,通过严格的品质控制,确保每一份食材都达到最高标准。此外,我们还提供... 点击进入详情页
本回答由亚果会提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式