javaweb怎么输出是值而不是地址呢?

前台表单确认后台输出怎么才能让它输出的是值而不是地址呢,重写了toString也还是不对呢

package com.epoint.demo;

import java.io.IOException;
import java.util.Enumeration;

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

/**
 * Servlet implementation class StudentServlet
 */
@WebServlet("/StudentServlet")
public class StudentServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public StudentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        //获取所有请求参数名称和值
        request.setCharacterEncoding("utf-8");
        Enumeration parameterNames =request.getParameterNames();
        while(parameterNames.hasMoreElements()) {
            String paramName = parameterNames.nextElement();
            String[] paramValue = request.getParameterValues(paramName);
            for(String value: paramValue) {
            System.out.println(paramName+":"+paramValue);
            }
        }
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
        
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

    @Override
    public String toString() {
        return "StudentServlet [getInitParameterNames()=" + getInitParameterNames() + ", getServletConfig()="
                + getServletConfig() + ", getServletContext()=" + getServletContext() + ", getServletInfo()="
                + getServletInfo() + ", getServletName()=" + getServletName() + ", getClass()=" + getClass()
                + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]";
    }


}


html>
<html>
<head>
<meta charset="UTF-8">
<title>表单页面title>
head>
<body>
<form action="StudentServlet" method="post">
姓名:<input type="text" id="username" name="username" />
br>
性别:<input type="radio" name="sex" value="1"/><input type="radio" name="sex" value="2"/>br>
生日:<input type="birthday" id="birthday" name="birthday"/>
br>
密码:<input type="password" id="password" name="password"/>
br>
技能:<select id="skills" name="skills" />
<option value="1">javaoption>
<option value="2">C++option>
<option value="3">Oracleoption>
<option value="4">JavaScriptoption>
<select/>
br>
爱好:<input name="hobby" type="checkbox" value="1"/>编程
<input name="hobby" type="checkbox" value="2"/>健身
<input name="hobby" type="checkbox" value="3"/>唱歌
<input name="hobby" type="checkbox" value="4"/>摄影
br>
<input type="submit" value="提交"/>
<input type="reset" value="重置"/>
form>
body>
html>

  • 那你 输出那里 倒是 输出 value呀, 还写数组干啥?

    img

帮你代码稍做了修改,你可以复制进去测试看看


package com.epoint.demo;
import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class StudentServlet
 */
@WebServlet("/StudentServlet")
public class StudentServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public StudentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        //获取所有请求参数名称和值
        request.setCharacterEncoding("utf-8");
        Enumeration<String> parameterNames =request.getParameterNames();
        while(parameterNames.hasMoreElements()) {
            String paramName = parameterNames.nextElement();
            String[] paramValue = request.getParameterValues(paramName);
            for(String value: paramValue) {
            System.out.println(paramName+":"+value);
            }
        }
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
    }
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
    @Override
    public String toString() {
        return "StudentServlet [getInitParameterNames()=" + getInitParameterNames() + ", getServletConfig()="
                + getServletConfig() + ", getServletContext()=" + getServletContext() + ", getServletInfo()="
                + getServletInfo() + ", getServletName()=" + getServletName() + ", getClass()=" + getClass()
                + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]";
    }
}