servlet的一些问题

a670910065 2013-06-29 05:04:22
ip.java

package com.claire.helloworld;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;

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

public class ip extends HttpServlet {
private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=gbk");
String a=request.getParameter("ip");
PrintWriter out = response.getWriter();
out.println("<form action=http://www.youdao.com/smartresult-xml/search.s?type=ip&q=><input type='text'name='q' id='ip' >");
out.println("<input type='submit' value='搜寻' id='tt'></form>");


}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet( request, response);
}


}


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>haha</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>ip</servlet-name>
<servlet-class>com.claire.helloworld.ip</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ip</servlet-name>
<url-pattern>/ip</url-pattern>
</servlet-mapping>
</web-app>



在ip.java中的输出的out.println("<form action=http://www.youdao.com/smartresult-xml/search.s?type=ip&q=><input type='text'name='q' id='ip' >");里面.点击提交的时候网站地址不对,type=ip&这几个不见了...该怎么弄.水平有限,学校实训的...找了好久找不到.求大虾...
...全文
165 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
那位先生_ 2013-06-30
  • 打赏
  • 举报
回复
引用 4 楼 a670910065 的回复:
[quote=引用 3 楼 ruochenxing 的回复:] out.println("<form action=‘http://www.youdao.com/smartresult-xml/search.s?type=ip&q=’"+q+"><input type='text'name='q' id='tt' >"); out.println("<input type='submit' value='搜寻' id='tt'></form>");
这个ip&q=’"+q+"不能用双引号吧..我改了单引号也不行..[/quote] 会报错?
侠龙 2013-06-29
  • 打赏
  • 举报
回复
最后加上 out.flush();out.close();out.flush();是将缓存中的数据,发送到客户端,也就是浏览器端,如果不调用out.flush()那么你的数据被保留字服务端的内存中,没有发送,也没有释放。并且你这样写具有非常大的安全隐患,如果多次调用,会导致后台内存溢出,tomcat可能就挂了。所以要加上out.flush();out.close();
你首先拿一个type参数先试试,看能不能进入到servlet后台,输出打印日志调试下 如果能进入servlet就说明不是配置的问题,可能是参数值的问题 我看你q后面跟这么一长串,是不是有些特殊字符需要转义的,先传个简单的参数试试看
wadiad 2013-06-29
  • 打赏
  • 举报
回复
先顶一个再说!
a670910065 2013-06-29
  • 打赏
  • 举报
回复
郁闷啊.等了好久啊.在线等的啊,拜托啊...!!!
a670910065 2013-06-29
  • 打赏
  • 举报
回复
没人懂吗?求教啊.!!!!!!!!!!!!!!!!!!!!!
a670910065 2013-06-29
  • 打赏
  • 举报
回复
引用 3 楼 ruochenxing 的回复:
out.println("<form action=‘http://www.youdao.com/smartresult-xml/search.s?type=ip&q=’"+q+"><input type='text'name='q' id='tt' >"); out.println("<input type='submit' value='搜寻' id='tt'></form>");
这个ip&q=’"+q+"不能用双引号吧..我改了单引号也不行..
那位先生_ 2013-06-29
  • 打赏
  • 举报
回复
out.println("<form action=‘http://www.youdao.com/smartresult-xml/search.s?type=ip&q=’"+q+"><input type='text'name='q' id='tt' >"); out.println("<input type='submit' value='搜寻' id='tt'></form>");
a670910065 2013-06-29
  • 打赏
  • 举报
回复
大虾呢?在哪里呢??!!!
小丑哥_V5 2013-06-29
  • 打赏
  • 举报
回复

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧