当前位置: 代码迷 >> Java Web开发 >> 怪事.
  详细解决方案

怪事.

热度:262   发布时间:2007-11-08 22:28:57.0
怪事.

我的JSP页面:

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="DBHandle.DBConn" %>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>

<body>
<div style="z-index:0;position:absolute;left:15px;top:5px;color:red";>
<font size=4> 公司介绍:</font><br>
&nbsp; &nbsp; &nbsp; &nbsp;重要提醒:贵公司的资料上网后会受到其他客户及工商质检部门等多方关注,请如实填写!<br>
&nbsp; &nbsp; &nbsp; &nbsp;因此虚假信息产生的相关责任,将由贵公司自行承担 (只能创建一个公司!)
</div>
<div style="z-index:0;position:absolute;left:15px;top:80px";>
<form action="Company_Servlet" method="post" enctype="multipart/form-data" id="form1" name="form" onsubmit="return check()">

<table width="750px" height=570px border=1 align=center cellpadding=2 cellspacing=0 style="word-break:break-all;" >
<caption align=left><font color=red>公司资料(带*号的为必须添)</font></caption>
<tr>
<td width="25%" align="right">公司名称:</td>
<td width="30%" >
<input name="companyName" id="NameId" type="text" size="20" maxlength="50" ></td>
<td width="45%"><font color=red>*</font>(请用中文完整填写在共商局注册的公司全称!)</td>
</tr>
<tr>
<td align="right">公司类型:</td>
<td>
<select name="companyType" style="width:155px";>
<option value="1">个体经营 </option>
<option value="2">私营企业 </option>
<option value="3">国有企业 </option>
<option value="4">股份公司 </option>
<option value="5">中外和资 </option>
</select>
</td>
<td><font color=red>*</font></td>
</tr>
<tr>
<td align="right">主营产品:</td>
<td>
<select name="mainProduct" style="width:155px";>
<option value="1">服装</option>
<option value="2">数码电子</option>
<option value="3">化装用品</option>
<option value="4">书籍/音响</option>
<option value="5">装饰品</option>
</select>
</td>
<td><font color=red>*</font>(请认真选择,会决定你发布的东西在哪类!)</td>
</tr>
<tr>
<td align="right">创立时间:</td>
<td><input name=createTime id="createTime" type="text" size=20 maxlength=16></td>
<td><font color=red>*</font>(你现有公司创立的年份,如:2004!)</td>
</tr>
<tr>
<td colspan="3" align=center><input type=submit value="提交"><input type=reset value="重置"></td>
</tr>
</table>
</form>
</div>
<script language='Javascript'>
function check(){
if(document.form.companyName.value==""){
alert("请填写公司名称!");
return false;
}
if (document.form.createTime.value==""){
alert("请填写创立时间!");
return false;
}
}

</script>
</body>
</html>
我的SERVLET:

package myServlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Company_Servlet extends javax.servlet.http.HttpServlet implements
javax.servlet.Servlet{

/**
*
*/
private static final long serialVersionUID = 5196096313704409848L;

public Company_Servlet(){
super();
}

public void doPost(HttpServletRequest request,HttpServletResponse response) throws
ServletException,IOException{
response.setContentType("text/html;charset=gb2312");
String method=request.getParameter("method");
String mycompanyName=request.getParameter("companyName");
String mycompanyType=request.getParameter("companyType");
String mymainProduct=request.getParameter("mainProduct");
String mycreateTime=request.getParameter("createTime");
String myprovince=request.getParameter("province");
String mycity=request.getParameter("city");
System.out.print(request.getParameter("companyName"));
System.out.print(mymainProduct);


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

我的WEB.XML
<servlet>
<servlet-name>companyInfo</servlet-name>
<servlet-class>myServlet.Company_Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>companyInfo</servlet-name>
<url-pattern>/Company_Servlet</url-pattern>
</servlet-mapping>

当我提交的时候,怎么打印出来的全是NULL啊,我添写了啊,不为空啊,怎么了啊?
哪位大哥帮帮看看,谢谢!!!
在线等..





搜索更多相关主题的帖子: 怪事  

----------------解决方案--------------------------------------------------------
大哥们看下啊,好简单的啊,代码可能多了点,麻烦了.....
----------------解决方案--------------------------------------------------------
去掉enctype="multipart/form-data";
使用默认的就可以了;
"multipart/form-data"是在文件传输时使用的~~~

----------------解决方案--------------------------------------------------------

恩,是这样哦,
我还有代码没贴出来啊,我是要上传文件的,那要怎么改啊??


----------------解决方案--------------------------------------------------------

完整的代码是::

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="DBHandle.DBConn" %>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'createCompany.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<%
Connection myconn=DBConn.getconn();
ResultSet rs=null;
ResultSet rs2=null;
Statement stmt=null;
String sql=null;
String sql2=null;
stmt=myconn.createStatement();
%>
<body>
<div style="z-index:0;position:absolute;left:15px;top:5px;color:red";>
<font size=4> 公司介绍:</font><br>
&nbsp; &nbsp; &nbsp; &nbsp;重要提醒:贵公司的资料上网后会受到其他客户及工商质检部门等多方关注,请如实填写!<br>
&nbsp; &nbsp; &nbsp; &nbsp;因此虚假信息产生的相关责任,将由贵公司自行承担 (只能创建一个公司!)
</div>
<div style="z-index:0;position:absolute;left:15px;top:80px";>
<form action="Company_Servlet" method="post" enctype="multipart/form-data" id="form" name="form" onsubmit="return check()">

<table width="750px" height=570px border=1 align=center cellpadding=2 cellspacing=0 style="word-break:break-all;" >
<caption align=left><font color=red>公司资料(带*号的为必须添)</font></caption>
<tr>
<td width="25%" align="right">公司名称:</td>
<td width="30%" >
<input name="companyName" id="NameId" type="text" size="20" maxlength="50" ></td>
<td width="45%"><font color=red>*</font>(请用中文完整填写在共商局注册的公司全称!)</td>
</tr>
<tr>
<td align="right">公司类型:</td>
<td>
<select name="companyType" style="width:155px";>
<option value="1">个体经营 </option>
<option value="2">私营企业 </option>
<option value="3">国有企业 </option>
<option value="4">股份公司 </option>
<option value="5">中外和资 </option>
</select>
</td>
<td><font color=red>*</font></td>
</tr>
<tr>
<td align="right">主营产品:</td>
<td><font color=red>*</font>(请认真选择,会决定你发布的东西在哪类!)</td>
</tr>
<tr>
<td align="right">创立时间:</td>
<td><input name=createTime id="createTime" type="text" size=20 maxlength=16></td>
<td><font color=red>*</font>(你现有公司创立的年份,如:2004!)</td>
</tr>
<tr>
<td align="right">创立地点:</td>
<td><font color=red>*</font>(请认真选择-省份/城市,你现有公司的地点) </td>
</tr>
<tr>
<td align="right">公司招牌:</td>
<td>
<input type=file name=file2 size=20 maxlength=20>
</td>
<td><font color=red>*</font>你可以上传自己公司的招牌..自己做的图片..</td>
</tr>
<tr>
<td align="right">对公司的描述:</td>
<td colspan="2"><textarea name=desc cols=60 rows=15></textarea></td>
</tr>
<tr>
<td colspan="3" align=center><input type=submit value="提交"><input type=reset value="重置"></td>
</tr>
</table>
</form>
</div>
<script language='Javascript'>
function check(){
if(document.form.companyName.value==""){
alert("请填写公司名称!");
return false;
}
if (document.form.createTime.value==""){
alert("请填写创立时间!");
return false;
}
}
</script>
</body>
</html>


----------------解决方案--------------------------------------------------------
Form中Enctype只能设置成"multipart/form-data";
lz可以用jspSmartUpload来做,包里有一个SmartUpload类;
就可以用YourSmartUpload.getRequest().getParameter("XXX");
来得到Form中的除了file之外的字段值,关于file它有专门的处理方式,
lz可以去找找相关的资料;
----------------解决方案--------------------------------------------------------
恩,谢谢哈,jspSmartUpload.jar不知道放哪了,好象放哪都没用,我又刚发了一贴子,你能帮我看看吗?
----------------解决方案--------------------------------------------------------
加入classpath试试;
----------------解决方案--------------------------------------------------------
好象还是没用哦,
----------------解决方案--------------------------------------------------------
  相关解决方案