如果是要取出全部的值.建議解析WEB.XML然后取值.如果是取某個(gè)特定的值可以用下面的:

成都創(chuàng)新互聯(lián)專注于中大型企業(yè)的成都做網(wǎng)站、成都網(wǎng)站建設(shè)和網(wǎng)站改版、網(wǎng)站營銷服務(wù),追求商業(yè)策劃與數(shù)據(jù)分析、創(chuàng)意藝術(shù)與技術(shù)開發(fā)的融合,累計(jì)客戶千余家,服務(wù)滿意度達(dá)97%。幫助廣大客戶順利對(duì)接上互聯(lián)網(wǎng)浪潮,準(zhǔn)確優(yōu)選出符合自己需要的互聯(lián)網(wǎng)運(yùn)用,我們將一直專注品牌網(wǎng)站制作和互聯(lián)網(wǎng)程序開發(fā),在前進(jìn)的路上,與客戶一起成長!
web.xml里面可以定義兩種參數(shù):
(1)application范圍內(nèi)的參數(shù),存放在servletcontext中,在web.xml中配置如下:xml 代碼
context-param
param-namecontext/param/param-name
param-valueavalible during application/param-value
/context-param (2)servlet范圍內(nèi)的參數(shù),只能在servlet的init()方法中取得,在web.xml中配置如下:xml 代碼
servlet
servlet-nameMainServlet/servlet-name
servlet-classcom.wes.controller.MainServlet/servlet-class
init-param
param-nameparam1/param-name
param-valueavalible in servlet init()/param-value
/init-param
load-on-startup0/load-on-startup
/servlet 在servlet中可以通過代碼分別取用:java 代碼
package com.test;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
public class TestServlet extends HttpServlet ...{
public TestServlet() ...{
super();
}
public void init() throws ServletException ...{
System.out.println("下面的兩個(gè)參數(shù)param1是在servlet中存放的");
System.out.println(this.getInitParameter("param1"));
System.out.println("下面的參數(shù)是存放在servletcontext中的");
System.out.println(getServletContext().getInitParameter("context/param"));
}
} 第一種參數(shù)在servlet里面可以通過getServletContext().getInitParameter("context/param")得到
第二種參數(shù)只能在servlet的init()方法中通過this.getInitParameter("param1")取得init-param屬于一個(gè)servlet所有,context-param屬于整個(gè)應(yīng)用程序所有 ,不僅是在servlet中可以得到,jsp文件中也可以得到.在jsp中config就相當(dāng)于這里的servletContext,%=config.getServletContext().getInitParameter("...") %.
action中ServletActionContext.getServletContext().getInitParameter("...").
步驟如下:
1、在web工程里面創(chuàng)建一個(gè)Servlet類,繼承HttpServlet,重寫doPost,doGet方法,在doPost方法中調(diào)用doGet方法;
2、在doGet方法中把要設(shè)置到j(luò)sp頁面的值存到request中;
3、在doGet方法中添加轉(zhuǎn)發(fā)到j(luò)sp頁面的代碼;
4、在jsp頁面中使用jstl標(biāo)簽獲取存入的值。
事例代碼如下:
Servlet類:
public class DemoServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setAttribute("name", "nameValue");
request.getRequestDispatcher("/demo.jsp").forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
jsp頁面:
%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%
%@ taglib prefix="c" uri="" %
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
html
head
titleDemo/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"
/head
body
${name }
/body
/html
其中,%@ taglib prefix="c" uri="" %表示導(dǎo)入jstl標(biāo)簽庫,沒導(dǎo)入的話無法使用jstl標(biāo)簽,使用jstl標(biāo)簽可以減少很多代碼量,導(dǎo)入jstl標(biāo)簽后就可以通過使用${}的方法來獲取值了。
你的input框的id必須保證唯一:
1. 改法如下:
input name="txtType" type="radio" id = "txtType1" value="單選"單選
input name="txtType" type="radio" id ="txtType2" value = "多選"多選
2. 取值方法,在JavaScript中:
var inputSingle = document.getElementById("txtType1").html();
var inputMultiple = document.getElementById("txtType2").html();
以下代碼可以打印出對(duì)象中每個(gè)元素
Object[] myobj = {1,2,3,4};
String str;
for(int i = 0; i myobj.length; i++){
Object obj = myobj[i];
str = obj.toString();
System.out.println(str);
}
其中:
Object[] myobj 得到對(duì)象數(shù)組
Object obj = myobj[i];得到對(duì)象數(shù)組中每個(gè)對(duì)象
str = obj.toString();將對(duì)象轉(zhuǎn)為字符串。轉(zhuǎn)換為其他類型時(shí)要注意出錯(cuò)處理,如元素為非數(shù)字類型,轉(zhuǎn)換為數(shù)字的情況
實(shí)現(xiàn)思路:本問題實(shí)際上是對(duì)char類型轉(zhuǎn)換的一個(gè)實(shí)例,可以通過以下方式實(shí)現(xiàn)(舉例的是抽取100次):publicclassTest_1{publicstaticvoidmain(String[]args){int[]i=newint[100];intcount=0;while(count=0t=65t=97t=0i[k]=9)System.out.print(i[k]+"");elseSystem.out.print((char)i[k]+"");}}}
select id="nidaye"
option value="黃瓜"黃瓜/option
option value="柿子"柿子/option
option value="蘋果"蘋果/option
/select
js代碼
var selected=document.getElementById("nidaye").value
if(XXXXX)
xxxxxx
else
xxxxxxx
標(biāo)題名稱:java取值代碼 java取余代碼
URL標(biāo)題:http://chinadenli.net/article46/hipoeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、全網(wǎng)營銷推廣、動(dòng)態(tài)網(wǎng)站、企業(yè)建站、網(wǎng)站設(shè)計(jì)、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)