ClientService.java
package com.soft.client;
import org.apache.axis.client.Service;
import javax.xml.rpc.ServiceException;
import java.net.MalformedURLException;
import org.apache.axis.client.Call;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import javax.xml.namespace.QName;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import java.rmi.RemoteException;
public class ClientService {
public ClientService() {
}
public UserDTO getUserDTO() {
String endpoint = "http://localhost:8080/WebModule/services/Myservice";
QName qset = new QName("urn:Myservice", "UserDTO");
QName qmethod = new QName("urn:Myservice", "getUserDTO");
Class clsUserDTO = UserDTO.class;
UserDTO dto = new UserDTO();
Service service = new Service();
try {
Call call = (Call) service.createCall();
call.registerTypeMapping(clsUserDTO, qset,
new BeanSerializerFactory(clsUserDTO, qset),
new BeanDeserializerFactory(clsUserDTO,qset));
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(qmethod);
call.setReturnClass(clsUserDTO);
dto = (UserDTO) call.invoke(new Object[] {});
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dto;
}
public static void main(String[] args) {
ClientService cs = new ClientService();
UserDTO user = cs.getUserDTO();
System.out.println(user.getPassword());
System.out.println(user.getUsername());
}
}
UserDTO.java
package com.soft.client;
public class UserDTO {
private String username;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
import java.util.Map.Entry;
private static Map oldvote=new HashMap();
...............................
ModelAndView mav = new ModelAndView();
String voteid = ServletRequestUtils.getRequiredStringParameter(request,
"voteid");
String ip = ServletRequestUtils.getStringParameter(request, "ip");
//遍歷HasMap
Boolean isoldvote=false;
Iterator it=oldvote.entrySet().iterator();
while(it.hasNext()){
Entry entry=(Entry) it.next();
Object key=entry.getKey();
Object value=entry.getValue();
if(key.equals(voteid)&&value.equals(ip)){
isoldvote=true;
break;
}
}
if (isoldvote) {
...............................
1.
<html>
?<head>
??<title>transPara.htm</title>
?</head>
<body>
?<form method="POST" action="acceptPara.jsp">
? ??<p align="center">
??姓 名:<input type="text" name="name" size="20"><br>
? ??年 齡: <input type="text" name="age" size="15"><br>
? ??性 別:
???<input type="radio" value="male" checked name="sex">
????男 ?
? ???<input type="radio" name="sex" value="female">女</p>
? ??<p align="center">
???<input type="submit" value="submit" name="submit">
? ???<input type="reset" value="reset" name="reset"></p>
?</form>
</body>
</html>
2.
<html>
<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="atest"? class="test.AcceptPara"/>
<head><title>acceptPara.jsp</title></head>
<body>
<jsp:setProperty name="atest" property="*"/>?? //? ***將javabean中的屬性自動與html提交過來的變量匹配***********
Value of property "name" :
<jsp:getProperty name="atest" property="name"/><br>
Value of property "age" :
<jsp:getProperty name="atest" property="age"/><br>
Value of property "sex" :
<jsp:getProperty name="atest" property="sex"/><br>
Value of property "submit" :
<jsp:getProperty name="atest" property="submit"/><br>
</body>
</html>
3.
package test;//?? 在一些tomcat舊版本包定義一定要有,且在jsp引用中如下:<jsp:useBean id="atest"? class="test.AcceptPara"/>? 編譯后放在\WEB-INF\classes\test\中
public class AcceptPara{
?String name;
?int age;
?String sex;
?String submit;
?
?public void setName(String value){
??name=value;
?}
?
?public String getName(){
??return name;
?}
?
?public void setAge(int value){
??age=value;
?}
?
?public int getAge(){
??return age;
?}
?
?public void setSex(String value){
??sex=value;
?}
?
?public String getSex(){
??return sex;
?}
?
?public void setSubmit(String value){
??submit=value;
?}
?
?public String getSubmit(){
??return submit;
?}
??
?public void acceptPara(){}
?
}