Eight.Java版 2022-12-20 16:16 采纳率: 83.3%
浏览 51
已结题

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<String> 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() + "]";
    }


}


<!DOCTYPE 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">java</option>
<option value="2">C++</option>
<option value="3">Oracle</option>
<option value="4">JavaScript</option>
<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>

  • 写回答

2条回答 默认 最新

  • Huazie 全栈领域优质创作者 2022-12-20 16:34
    关注
    • 那你 输出那里 倒是 输出 value呀, 还写数组干啥?

      img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月28日
  • 已采纳回答 12月20日
  • 创建了问题 12月20日

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装