protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String username = new String(request.getParameter("username").getBytes("ISO-8859-1"), "GBK"); String filePath = new String(request.getParameter("filePath").getBytes("ISO-8859-1"), "GB2312"); String fileName = new String(request.getParameter("fileName").getBytes("ISO-8859-1"), "GB2312"); //String path = "/user/hadoop/zhangsan/"; String path = "/user/fxb/favor/" + username + "/"; }
时间: 2023-07-21 08:01:06 浏览: 67
根据您提供的代码片段,您正在使用HttpServletRequest对象的getParameter方法来获取URL参数。在这种情况下,如果getParameter方法返回null,可能是以下原因之一导致的:
1. 参数未正确传递:请确保在URL中正确传递了名为"username"、"filePath"和"fileName"的参数。
2. 参数编码问题:您正在使用getBytes方法将参数从ISO-8859-1编码转换为GBK或GB2312编码。请确保编码转换正确,并且与请求参数的实际编码一致。
3. 参数名称错误:请检查参数名称是否正确拼写,并且与URL中的参数名称完全匹配。
请注意,您在代码中给出的路径变量path没有被使用,如果您希望使用该路径,请确保在适当的位置使用它。
如果问题仍然存在,请提供更多关于请求和响应的细节,以便我们更好地帮助您解决问题。
相关问题
@WebServlet("/introduceUrl") public class IntroduceController extends HttpServlet { private static final long serialVersionUID = 1L; public IntroduceController() { super(); // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.getRequestDispatcher("/WEB-INF/pages/introduce.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
这是一个使用 Servlet 技术实现的介绍控制器,它提供了 doGet() 和 doPost() 两个方法来处理 GET 和 POST 请求。在 doGet() 方法中,它直接将请求转发到 "/WEB-INF/pages/introduce.jsp" 页面进行展示。在 doPost() 方法中,它直接调用 doGet() 方法来处理请求。该控制器没有实际的业务逻辑,只是用来展示介绍页面。
@WebServlet("/admin/addScore") public class AddScoreController extends HttpServlet { private static final long serialVersionUID = 1L; public AddScoreController() { super(); // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String isbn = request.getParameter("isbn"); String courseName = request.getParameter("courseName"); String className = request.getParameter("className"); String num = request.getParameter("num"); Score score = new Score(); score.setIsbn(isbn); score.setCourseName(courseName); score.setClassName(className); score.setNum(Integer.valueOf(num)); ScoreService scoreService = new ScoreService(); scoreService.addScore(score); request.getRequestDispatcher("/admin/tecoursesUrl").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
这是一个Java Servlet,用于处理添加成绩的请求。根据请求中的参数,创建一个Score对象,设置其属性,并将其传递给ScoreService进行添加。然后,将请求重定向到"/admin/tecoursesUrl"页面。其中,doGet()方法处理HTTP GET请求,doPost()方法处理HTTP POST请求。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)