小编use*_*441的帖子

Servlet HTTP 500 - NullPointerException

我刚刚开始使用J2E.

NullPointerException排队了:

if (!userName.equals("") && userName != null)
Run Code Online (Sandbox Code Playgroud)

当我像这样运行服务器:

http://localhost:8080/SimpleServletProject/SimpleServletPath?name=test
Run Code Online (Sandbox Code Playgroud)

它完美地运作.但不接受null.

整码:

package org.mojservlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@WebServlet("/SimpleServletPath")
public class SimpleServlet extends HttpServlet {
private static final long serialVersionUID = 1L;


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("get method");
    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    String userName = request.getParameter("name");
    HttpSession session = request.getSession();
    ServletContext context = request.getServletContext();
    if (!userName.equals("") && …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
227
查看次数

标签 统计

java ×1