環境 eclipse tomcat6
javaファイルとweb.xmlを用いており
職業を選択し送信ボタンを押すとあなたの職業はXXXですと表示するはずなのですが
HTTPステータス 404がでて困っています
どこが間違っているのでしょうか
package servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class RadioInput extends HttpServlet{
String html;
String html1="<!doctype html><html lang=ja><head><meta charset=utf-8><title>Radioinput</title></head></body>";
String html2="職業をお選びください<form action=Radioinput method=post><table><tr><td><input type=radio name=occupation value=会社員>会社員<br><input type=radio name=occupation value=学生>学生<br><input type=radio name=occupation value=主婦>主婦<br><input type=radio name=occupation value=その他>その他</td></tr></table><br><input type=submit value =送信><input type=reset value=リセット></form></body></html>";
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
html=html1+html2;
out.println(html);
out.close();
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
int numberOfErrors=0;
String errorMessage="<div class=alerm>入力値にエラーがありました</div>";
String noRadioValueError="<div class=alerm>「エラー入力値がありません」</div>";
request.setCharacterEncoding("UTF-8");
String occupation=request.getParameter("occupation");
if(occupation==null){
numberOfErrors +=1;
errorMessage +=noRadioValueError;
}
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
if(numberOfErrors>0){
html = html1+errorMessage+html2;
out.println(html);
}else{
html=html1+"あなたの職業は"+occupation+"ですね</body></html>";
out.println(html);
}
out.close();
}
}
No.2ベストアンサー
- 回答日時:
## String html2="職業をお選びください<form action=Radioinput method=post> ・・・
の部分ですが、
String html2="職業をお選びください<form action='./RadioInput' method=post>
でどうですか?
あと、大きなお世話かもしれませんけど、メンバー変数の
String html
ですが、勉強レベルなら構いませんがsynchronizedとかしないと複数からリクエストがあった時、
同じ結果が複数のクライアントへ表示されてしまう場合がありますよ。
特に問題がなさそうなので、ローカル変数としてしまうのも手ですね。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・14歳の自分に衝撃の事実を告げてください
- ・架空の映画のネタバレレビュー
- ・「お昼の放送」の思い出
- ・昨日見た夢を教えて下さい
- ・【お題】絵本のタイトル
- ・【大喜利】世界最古のコンビニについて知ってる事を教えてください【投稿~10/10(木)】
- ・メモのコツを教えてください!
- ・CDの保有枚数を教えてください
- ・ホテルを選ぶとき、これだけは譲れない条件TOP3は?
- ・家・車以外で、人生で一番奮発した買い物
- ・人生最悪の忘れ物
- ・【コナン30周年】嘘でしょ!?と思った○○周年を教えて【ハルヒ20周年】
- ・ハマっている「お菓子」を教えて!
- ・最近、いつ泣きましたか?
- ・夏が終わったと感じる瞬間って、どんな時?
- ・10秒目をつむったら…
- ・人生のプチ美学を教えてください!!
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・都道府県穴埋めゲーム
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
iframeの中でページ内リンクは...
-
相対パスから絶対パスの取得
-
メール本文に変な文字が
-
この鐘状の花の名前は何でしょ...
-
lang 英語と日本語など混ざる時は
-
腎障害の食事療法
-
仙台からの日帰り入浴
-
エアジョーダン6 カーマインを...
-
マカロンって常温だとどれくら...
-
日本人20歳男身長170cm...
-
田んぼの稲刈り
-
日サロSOLE
-
googlemapapi複数マーカー10個...
-
桐蔭学園卒業生があつまるBBS
-
アメリカの最初に独立した13州...
-
Excelで、社外秘(閲覧のみ)と...
-
HTMLからフォルダを開きたい
-
htmlファイルの表示が真っ白
-
VBA URLDownloadToFileについて
-
googleドライブで、PDFファイル...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
Excel VBA :URLの中で変数を使...
-
中埜酢店 のよみかた
-
lang 英語と日本語など混ざる時は
-
ベーシック認証時、キャンセル...
-
html4.01とxhtmlではレスポンシ...
-
javaでhtmlファイルを開く方法
-
メール本文に変な文字が
-
京都駅から延暦寺へのアクセス
-
相対パスから絶対パスの取得
-
You Are The Sunshine Of My Li...
-
桐蔭学園卒業生があつまるBBS
-
<HTML>タグについて
-
インラインフレームの横スクロ...
-
複数のファイルをdiffで比較す...
-
デキャンタをさがしています(...
-
HTMLの内容をテキストエリアに...
-
磯野貴理子について
-
この鐘状の花の名前は何でしょ...
-
甲府市にあった穂積という料亭...
-
iframeの中のページのリンクを...
おすすめ情報