zoukankan      html  css  js  c++  java
  • Struts2的返回结果怎么总是input

    不得不感慨,解决问题的能力实在是弱爆了,一个这么小的问题,解决了好几天,本以为是框架出现了问题,又重新换了框架,没想到是这个问题

    我写的是一个服装的网站,在后台需要添加产品,页面代码如下

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <%@ page import="com.cloth.cache.PageProperties" %>
    <%@ page import="com.cloth.cache.*,com.cloth.modelBase.PageListInfo,com.cloth.pojo.*" %>
    <%
    String path = request.getContextPath();
    String context = request.getScheme() + "://"
    + request.getServerName() + ":" + request.getServerPort()
    + path + "/";
    PageProperties properties = new PageProperties();
    List categoryList = ((PageListInfo)request.getAttribute("categoryListInfo")).getList();
    Product product = null;
    Category category = null;
    %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
    <!--
    body {
    margin-left: 3px;
    margin-top: 0px;
    margin-right: 3px;
    margin-bottom: 0px;
    }

    .STYLE1 {
    color: #e1e2e3;
    font-size: 12px;
    }

    .STYLE6 {
    color: #000000;
    font-size: 12;
    }

    .STYLE10 {
    color: #000000;
    font-size: 12px;
    }

    .STYLE19 {
    color: #344b50;
    font-size: 12px;
    }

    .STYLE21 {
    font-size: 12px;
    color: #3b6375;
    }

    .STYLE22 {
    font-size: 12px;
    color: #295568;
    }
    -->
    </style>
    <script language="javascript" type="text/javascript" src="<%=context %>admin/jsp/fckeditor/fckeditor.js"></script>
    <script language="javascript" type="text/javascript">
    function doAdd(){
    var name = document.getElementById("product.name").value;
    var description = document.getElementById("product.description").value;
    var parent = document.getElementById("product.categoryName");
    var parentValue = parent.options[parent.options.selectedIndex].value;
    if(name == ""){
    alert("请输入服饰名称!");
    return false;
    }
    if(parentValue == "0"){
    alert("请选择所属分类");
    return false;
    }
    if(description == ""){
    alert("请输入相关描述!");
    return false;
    }
    return true;
    }
    </script>
    </head>

    <body>
    <span id="errorSpan" style="color:red"></span>
    <s:actionerror cssStyle="color:red"/>
    <table width="100%" border="0" align="center" cellpadding="0"
    cellspacing="0">
    <tr>
    <td height="30">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td height="24" bgcolor="#353c44">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>
    <table width="100%" border="0" cellspacing="0"
    cellpadding="0">
    <tr>
    <td width="6%" height="19" valign="bottom">
    <div align="center">
    <img src="<%=context %>admin/images/tb.gif" width="14" height="14" />
    </div>
    </td>
    <td width="94%" valign="bottom">
    <span class="STYLE1"><%=properties.getValue("product.add") %></span>
    </td>
    </tr>
    </table>
    </td>
    <td>
    <div align="right">
    <span class="STYLE1"> <input type="checkbox"
    name="checkbox11" id="checkbox11" /> <%=properties.getValue("system.selectAll") %> &nbsp;&nbsp;<img
    src="<%=context %>admin/images/add.gif" width="10" height="10" /> <%=properties.getValue("system.add") %> &nbsp;
    <img src="<%=context %>admin/images/del.gif" width="10" height="10" /> <%=properties.getValue("system.delete") %>
    &nbsp;&nbsp;<img src="<%=context %>admin/images/edit.gif" width="10"
    height="10" /> <%=properties.getValue("system.edit") %> &nbsp;</span><span class="STYLE1">
    &nbsp;</span>
    </div>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td>
    <%--<s:form action="productAction!add.action" method="post" name="frmAction"
    enctype="multipart/form-data">
    --%>
    <form action="productAction!add.action" method="post" name="frmAction">
    <table width="100%" border="0" align="center" cellpadding="0"
    cellspacing="1" bgcolor="d5d4d4">
    <tr>
    <td height="22" colspan="4" background="<%=context %>admin/images/background.gif"
    bgcolor="#FFFFFF" style="font-size: 12px; font-weight: bold;">
    <div align="center">
    <%=properties.getValue("product.add") %>
    </div>
    </td>
    </tr>
    <tr>
    <td colspan="4" bgcolor="#FFFFFF" style="font-size: 12px">
    <table width="70%" border="0" align="center" cellpadding="0"
    cellspacing="0">
    <tr>
    <td width="142" height="35" style="font-size: 12px" nowrap="nowrap">
    <div align="left">
    <%=properties.getValue("product.name") %>
    </div>
    </td>
    <td height="35" colspan="3" style="font-size: 12px">
    <div align="left">
    <input type="text" name="product.name" id="product.name"
    style=" 500px; height: 17px; font-size: 12px; border: solid 1px #ccc;" />
    </div>
    </td>
    </tr>
    <tr>
    <td width="142" height="35" style="font-size: 12px" nowrap="nowrap">
    <div align="left">
    <%=properties.getValue("product.indexPic") %>
    </div>
    </td>
    <td height="35" colspan="3" style="font-size: 12px">
    <div align="left">
    <select name="product.indexPic" id="product.indexPic"
    style=" 200px; height: 17px; font-size: 12px;">
    <option selected="selected" value="1">
    <%=properties.getValue("system.yes") %>
    </option>
    <option value="0">
    <%=properties.getValue("system.no") %>
    </option>
    </select>
    </div>
    </td>
    </tr>
    <tr >
    <td width="142" height="35" style="font-size: 12px" nowrap="nowrap">
    <div align="left">
    <%=properties.getValue("product.categoryId") %>
    </div>
    </td>
    <td height="35" colspan="3" style="font-size: 12px">
    <div align="left">
    <select name="product.categoryId" id="product.categoryId"
    style=" 200px; height: 17px; font-size: 12px;">
    <option selected="selected" value="0">
    ==请选择==
    </option>
    <%
    String value = null;;
    for(int i=0;i<categoryList.size();i++){
    category = (Category) categoryList.get(i);
    value = category.getId()+","+category.getName();
    %>
    <option value='<%=value %>'>
    <%=category.getName() %>
    </option>
    <%
    }
    %>
    </select>
    </div>
    </td>
    </tr>
    <tr>
    <td width="142" height="35" style="font-size: 12px" nowrap="nowrap">
    <div align="left">
    <%=properties.getValue("product.picture") %>
    </div>
    </td>
    <td height="35" colspan="3" style="font-size: 12px">
    <div align="left">
    <s:file name="product.picture"></s:file>
    </div>
    </td>
    </tr>
    <tr >
    <td height="35">
    </td>
    </tr>
    <tr>
    <td width="142" height="35" style="font-size: 12px" nowrap="nowrap">
    <div align="left">
    <%=properties.getValue("product.description") %>
    </div>
    </td>
    <td height="35" colspan="3" style="font-size: 12px">
    <div align="center">
    <textarea rows="20" cols="110" id="product.description" name="product.description"></textarea>
    </div>
    </td>
    </tr>
    <tr>
    <td height="40" style="font-size: 12px">
    &nbsp;
    </td>
    <td height="35" colspan="3" style="font-size: 12px" align="center">
    <input type="submit" value="确定" onclick="return doAdd()"/>
    <input type="reset" value="取消"/>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    <%--</s:form>
    --%>
    </form></td>
    </tr>
    </table>
    </body>
    </html>

    可是提交表单的时候返回的结果却总是input,无语了,到底是怎么回事啊???我用了无数的方法,就是找不出来,结果Google到了这篇文章<http://bbs.csdn.net/topics/350063386>,楼主的答案彻底把我杀死。我在页面要传递两个参数到后台,但是在select里面却无法实现,只好把它亲结成一个字符串进行传递,参数名称是categoryId,问题就出现在了这里,由于categoryId是Integer类型的,所以后台老是出现转换异常,但是控制台也不把这种异常打印出来,所以。。。。。

  • 相关阅读:
    Ubuntu打开终端的方法三种
    javascript 获取随机数
    HTML5中类jQuery选择器querySelector的使用
    PHP stream_context_create()作用和用法分析
    一些常用的api接口、
    怎么样学好C++
    指针访问与数组访问的效率分析
    架构师
    Java 之 StringTokenizer
    类型转换操作符static_cast、const_cast、dynamic_cast、reinterpret_cast
  • 原文地址:https://www.cnblogs.com/yurujun/p/3077763.html
Copyright © 2011-2022 走看看